Selecting elements by text with CSS3 selectors in CasperJS


I’m doing functional testing using CasperJS’s test class, and can’t seem to select elements by their text values. My goal is to check that a class of div is visible, and then check it has the value I expect.

I’ve tried using the CSS3 selectors mentioned on CaspersJS’ selector page, but must be doing something wrong. None of the following work for me (all enclosed in ""):

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

Any pointers as to how I can select a specific element based on it’s text value?

Problem courtesy of: rowanu


Thanks for the comments above — I ended up going with using jQuery (as it was being loaded on the client) through evaluate() calls in the CasperJS tests.

Solution courtesy of: rowanu

View additional discussion.