How to print error after webdriverwait.until is been used

For my iOS Automation,

I wanted to check if an element is present. more like a wait command.

So its like -

html_source = wd.page_source
if element not in html_source:
WebDriverWait(wd, 20).until(EC.presence_of_element_located((By.NAME, element)))
print " error in locating element"

But whenever i try running this to find an element not present, It waits for 20 seconds and quits, It never prints the error message . So what should i need to do to print the error message, if the element is not found?

Any help ?

catch the exception thrown by WebDriverWait method/interface

try{
WebDriverWait(wd, 20).until(EC.presence_of_element_located((By.NAME, element)))
}
catch (Exception e)
{
print " error in locating element"
System.out.println(e.getMessage()); // to print actual exception occured
}

1 Like