Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

waitForAndFindElement by js expression syntax

synthetics
java
configuration
synthetics-script

#1

Is this correct syntax for the js expression?

return $browser.waitForAndFindElement(
    $driver.By.js("document.getElementsByClassName('button-add-compare')[0]"))
    .then(function(e) {
        e.click();
    });

I get this error…

TaskTimedOut: Task timed-out waiting for element to be located using: function(driver) {

Yet the following code appears to work correctly…

return $browser.executeScript("document.getElementsByClassName('button-add-compare')[0].click();");


#2

Hi, @william.krick: See if this helps: http://mooshynmuffin.com/wordpress/blog/2016/12/29/using-by-js-selector-with-webdriver-javascript/


#3

Thanks. I was missing the “return” at the beginning of the expression…

return $browser.waitForAndFindElement(
    $driver.By.js("return document.getElementsByClassName('button-add-compare')[0]"))
    .then(function(e) {
        e.click();
});