Selecting elements by text using CSS3 selectors in CasperJS

I am doing functional testing using the CasperJS test class and cannot display elements by their text values. My goal is to check that the div class is visible, and then check if it has the value that I expect.

I tried using the CSS3 selector mentioned on the Kaspers Selector page , but should be doing something wrong. None of the following actions for me (everything is enclosed in "" ):

  • div#myid[text()='sometext']
  • div#myid[text='sometext']
  • div#myid[text=sometext]
  • div#myid:contains('sometext')
  • div#myid:contains(sometext)

Any pointers to how I can select a specific element based on its text value?

+4
source share
2 answers

Thanks for the comments above - I ended up using jQuery (since it was loaded on the client) via evaluate() calls in evaluate() tests.

+1
source

Try:

 var x = require('casper').selectXPath; this.test.assertExists(x('//*[@id="myid"][text()="sometext"]'), 'the element exists'); 
+4
source

All Articles