我使用的是java try
和catch
。如果元素不存在,我需要跳到下一步
我在try
块中尝试了以下操作:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
但是得到了以下错误:
org.openqa.selene.remote.ErrorHandler$UnknownServerException:元素当前不可见,因此可能无法与`交互
您可以尝试以下操作:
WebDriverWait wait = new WebDriverWait(driver,20);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id of the element to be located")));
return SUCCESS;
} catch (NoSuchElementException exception) {
return FAILURE;
}
如果返回为SUCCESS
,则执行下一行,否则跳过它。