Ali*_*adi 0 java 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;
}
}
Run Code Online (Sandbox Code Playgroud)
它在找到元素时返回 true,但在未找到元素时抛出异常,我如何使方法返回 false 而不是抛出异常,或者是否有更好的布尔值方法或方法可以为我完成这项工作.
亲切的问候
李在轩回答了这个问题
{
wait.until( ... ); return true;
}
catch(TimeoutException ex)
{ return false; } //might work if the wait.until( ... ) throws a TimeoutException
Run Code Online (Sandbox Code Playgroud)
报告说没有