I am trying to use casperjs to check if the following element exists in the DOM:
<b>Bar</b>
Is there a simple way to do that using selectors and casper.exists
? The casperjs documentation makes it very unclear.
The basic use of casper.exists()
is to pass it a selector string and it'll return true or false to indicate whether any elements were found to match that selector.
In your case, however, the only practical selector that would find this element is b
, so if you're specifically looking for a b
element containing this text then you'll need to either specify some form of context (e.g. a parent element), or test this element's existence using XPath instead, which lets you test elements by their text content:
var x = require('casper').selectXPath;
if (casper.exists(x('//b[text()="Bar"]'))) {
// <b>Bar</b> exists
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With