如何使我使用Wait.Until的方法忽略在Selenium WebDriver中引发异常
问题描述:
我有一个方法
private boolean findElements(
String xpath,
int timeOut ) {
WebDriverWait wait = new WebDriverWait( driver, timeOut );
try {
if( wait.until( ExpectedConditions.visibilityOfElementLocated( By.xpath( xpath ) ) ) != null ) {
return true;
} else {
return false;
}
} catch( NoSuchElementException e ) {
e.printStackTrace();
return false;
}
}
在找到元素时返回true,但在找不到元素时抛出异常,我如何使方法返回false而不是throwing异常,或者是否有更好的布尔方法或方法可以做到我的工作.
it returning true when element is found but it throwing an exception when element is not found, how can i make the method returning false instead of the exception throwing , or is there a better way or method that is boolean which can do the job for me.
亲切的问候
答
Jae Heon Lee回答了
Jae Heon Lee answered this question
{
wait.until( ... ); return true;
}
catch(TimeoutException ex)
{ return false; } //might work if the wait.until( ... ) throws a TimeoutException
报告没有