我有一个像这样的元素:
<span class="myTest">Estimates</span>
如何使用XPath选择此选项?这就是我所拥有的:
x("//*[contains(@class,'myTest')][normalize-space(text())='Estimates']")
答案 0 :(得分:1)
您的选择器实际上是正确的,这是使用casperjs master分支的简短测试:
var x = require('casper').selectXPath;
casper.test.begin('your selector is okay', 1, function(test) {
casper.start().setContent('<span class="myTest">Estimates</span>');
test.assertExists(x("//*[contains(@class,'myTest')][normalize-space()='Estimates']"));
test.done();
});
演示:
$ casperjs test test-xpath.js
Test file: test-xpath.js
# your selector is okay
PASS Found an element matching: xpath selector: //*[contains(@class,'myTest')][normalize-space()='Estimates']
PASS 1 tests executed in 0.118s, 1 passed, 0 failed.