Reputation: 133
I am new to Selenium web drive. Trying to do some page automation and are using driver.wait
functions to wait for a selector rendering first and then do some operations later.
Was wondering if Selenium has a way to pass in a timeout handler to manage timeout if the element is not showing up after x seconds.
Here's my code:
driver.wait(function () {
return driver.isElementPresent(webdriver.By.css('input[id="searchMap"]'));
}, 10000);
So after 10 secs if input[id="searchMap"]
does not show up, Selenium script will end and Error is thrown.
I am looking for something like this:
driver.wait(function () {
return driver.isElementPresent(webdriver.By.css('input[id="searchMap"]'));
}, 10000, function fail(){
console.log("Time is up!");
});
Upvotes: 0
Views: 1280
Reputation: 133
Found a solution myself. Have to use catch
for Selenium promise
class.
Here is my code:
driver.wait(function () {
return driver.isElementPresent(webdriver.By.css('div.info-page'));
}, 10000).catch(function(e){
console.log('Catching Error');
});
Upvotes: 1