我正在使用 javatry
和catch
. 如果该元素不存在,我需要跳到下一步
我在块内尝试了以下内容try
:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
但出现以下错误:
org.openqa.selenium.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
则执行下一行,否则跳过它。