1

我有一个像这样的元素:

<span class="myTest">Estimates</span>

如何使用 XPath 来选择它?这就是我所拥有的:

x("//*[contains(@class,'myTest')][normalize-space(text())='Estimates']")
4

1 回答 1

1

您的选择器实际上是正确的,这是使用 casperjs 主分支的简短测试:

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.
于 2013-02-07T16:08:38.090 回答