我正在使用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}]}
答案 0 :(得分:4)
尝试使用:
casper.test.assertExists(div[class*="letters"]);
(如果您没有其他以“字母”开头的课程)
http://www.w3schools.com/cssref/css_selectors.asp
但我认为你有三个不同的类:
casper.test.assertExists('div.letters.vcard.known');