Reputation: 563
It is possible to wait until an element is present on a page with browser.wait(EC.presenceOf(element(by.id("button"))), 5000, "button not found")
This will throw an error when the element is not found on the page. I do not want this function to throw an error, instead it should return false
if the element is not found after 5 seconds.
How can I achieve this?
Upvotes: 1
Views: 544
Reputation: 36
you can try using if else block around with isdisplayed() function like
if(driver.findElement(By.xpath(noRecordId)).isDisplayed()){
return true;
}
else{
return false;
}
you can use boolean variable in place of return to save result.
Upvotes: 0
Reputation: 2348
One approach you can attempt to achieve this is by using standard try/catch's. This will catch the exception that is produced from the browser.wait and handle it in the catch.
try{
browser.wait(EC.presenceOf(element(by.id("button"))), 5000, "button not found")
}catch(){
return false;
};
Upvotes: 3