Question

I'm using CasperJS, and need to select a class that contains spaces. Did some googling but not getting what's going wrong.

HTML content :

<div id="member-1" class="letters vcard known"> 
 ...
</div>

CasperJS assertion

casper.test.assertExists('div.letters vcard known');

Also tried

casper.test.assertExists('div.letters\ vcard\ known');

Results

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}]}
Was it helpful?

Solution

Try using this :

casper.test.assertExists(div[class*="letters"]);

(if you don't have others class beginning with 'letters')

http://www.w3schools.com/cssref/css_selectors.asp

But i think you have three differents class so :

casper.test.assertExists('div.letters.vcard.known');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top