Reputation:
I'm using selenium-webdriver, waiting for a page to load and checking with driver.wait
(waiting for a tag to show up).
Two things
Is there a way to handle the error from hitting the timeout on driver.wait
(to stop it from crashing the server)?
And since I'm starting to suspect that approach is inappropriate, would this be a good place to just use driver.sleep
and then use driver.findElement
to check if the tag is present?
Thanks!
Upvotes: 0
Views: 1800
Reputation:
Using promises, I found a solution to my problem:
driver.wait(webdriver.until.elementLocated(webdriver.By.tagName(selector)), 10 * 1000, "Timed out")
.catch(function(e){
if (e.message.match("Timed out")){
return e;
} else {
throw e;
}
})
.then(function(e){
if (e.message && e.message.match("Timed out")){
driver.quit();
} else {
[functional code]
});
}
});
This is somewhat unwieldy, since selenium-webdriver just uses throw error
instead of a named error on timeout. But it seems better than using driver.sleep
.
Upvotes: 1