CasperJS waitUntilVisible by Xpath

758 Views Asked by At

Just started working with CasperJS, writing a few sample tests. Everything works fine when using CSS Selectors, however I'm having trouble using Xpath. The only reason I want to use xpath is to create a more resilient locator, i.e.

'//a[text()="Office Building"]' versus the css version: #content > div > div > div > div:nth-child(1) > a

Here's what I've tried (Note: I have tested this xpath in the browser console):

Tried passing directly

casper.waitUntilVisible('//a[text()="Office Building"]');

Tried specifying the locator explicitly as Xpath:

casper.waitUntilVisible({
    type: 'xpath',
    path: '//a[text()="Office Building"]'
});

And tried requiring the helper selectXPath from the module as documented here:

var x = require('casper').selectXPath;
casper.waitUntilVisible(x('//a[text()="Office Building"]'))';

All of these result in a timeout error Wait timeout of 30000ms expired, exiting. because the element is never "found". Any ideas?

1

There are 1 best solutions below

0
dasmelch On BEST ANSWER

This could be a solution if you are only got text as identifier for waiting and clicking a link in casperjs without using xPath.
It's more simple to wait for the text and then use clickLabel (if the text is unique):

casper.start('http://yourTestUrl.com');

casper.then(function() {
    casper.waitForText('Office Building');
});

casper.then(function() {
    casper.clickLabel('Office Building');
});

casper.run();