我正在使用 CasperJS,需要选择一个包含空格的类。进行了一些谷歌搜索,但没有发现问题所在。
HTML 内容:
<div id="member-1" class="letters vcard known">
...
</div>
CasperJS 断言
casper.test.assertExists('div.letters vcard known');
也试过
casper.test.assertExists('div.letters\ vcard\ known');
结果
FAIL Found an element matching: div.letters vcard known
# type: assertExists
# subject: false
# selector: "div.letters vcard known"
[warning] [phantom] looks you did not use begin() which is mandatory since 1.1
⚠ looks you did not use begin() which is mandatory since 1.1
FAIL AssertionError: Found an element matching: div.letters vcard known
# type: error
# subject: false
# error: {"message":"Found an element matching: div.masthead vcard contact","name":"AssertionError","result":{"success":false,"type":"assertExists","standard":"Found an element matching: div.letters vcard known","file":null,"doThrow":true,"values":{"subject":false,"selector":"div.letters vcard known"},"suite":"Untitled suite in null","time":1},"line":301,"sourceId":166856896,"sourceURL":"../modules/tester.js","stack":"AssertionError: Found an element matching: div.letters vcard known\n at assert (../modules/tester.js:301)\n at assertExists (../modules/tester.js:493)\n at sourceToJSON.js:41\n at runStep (../modules/casper.js:1518)\n at checkStep (../modules/casper.js:368)","stackArray":[{"function":"assert","sourceURL":"../modules/tester.js","line":301},{"function":"assertExists","sourceURL":"../modules/tester.js","line":493},{"sourceURL":"sourceToJSON.js","line":41},{"function":"runStep","sourceURL":"../modules/casper.js","line":1518},{"function":"checkStep","sourceURL":"../modules/casper.js","line":368}]}
最佳答案
尝试使用这个:
casper.test.assertExists(div[class*="letters"]);
(如果你没有其他以“字母”开头的类)
http://www.w3schools.com/cssref/css_selectors.asp
但我认为你有三个不同的类所以:
casper.test.assertExists('div.letters.vcard.known');
关于javascript - casperJS assertExists 不传递带有空格的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22447073/