Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选择XPath类和span元素的文本_Xpath_Selector_Casperjs - Fatal编程技术网

选择XPath类和span元素的文本

选择XPath类和span元素的文本,xpath,selector,casperjs,Xpath,Selector,Casperjs,我有这样一个元素: <span class="myTest">Estimates</span> 您的选择器实际上是正确的,下面是一个使用casperjs主分支的简短测试: var x = require('casper').selectXPath; casper.test.begin('your selector is okay', 1, function(test) { casper.start().setContent('<span class="m

我有这样一个元素:

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

您的选择器实际上是正确的,下面是一个使用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主分支的简短测试:

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();
});

这不管用吗?你收到错误信息了吗?你得到的结果不是你期望的吗?您的XPath乍一看是合法的(尽管我会用
[normalize-space()='Estimates']
替换第二个谓词,使其更简短、更惯用);怎么了?嗯,我的casperjs脚本说它找不到那个元素。我也在尝试这样做://div[@id='ctl00\u cphLeftPanel\u mi_assessments\u stderrors'和@class='level\u 2\u active']是的,CasperJS没有突出显示并正确查找我的元素肯定有问题。span元素在哪个命名空间中?XHTML?或者根本没有名称空间?这不起作用?你收到错误信息了吗?你得到的结果不是你期望的吗?您的XPath乍一看是合法的(尽管我会用
[normalize-space()='Estimates']
替换第二个谓词,使其更简短、更惯用);怎么了?嗯,我的casperjs脚本说它找不到那个元素。我也在尝试这样做://div[@id='ctl00\u cphLeftPanel\u mi_assessments\u stderrors'和@class='level\u 2\u active']是的,CasperJS没有突出显示并正确查找我的元素肯定有问题。span元素在哪个命名空间中?XHTML?或者根本没有名称空间?
$ 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.