I'm struggling to find a way to wait for an element to load in a javascript selenium test script. The closest thing I've come across is until.elementLocated
, but it seems to throw an immediate exception.
Is there a method to delay throwing the "NoSuchElementError" exception until the timeout has expired?
"NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()='NEXT']"}"
Or is there any way to avoid this exception altogether when waiting for an element in Selenium?
await driver.wait(function () {
let text = "//button[text()='" + "NEXT" + "']";
let button = By.xpath(text);
return until.elementLocated(button);
}, 40000).then(() => {console.log("element is located")})