-1

我正在使用 javatrycatch. 如果该元素不存在,我需要跳到下一步

我在块内尝试了以下内容try

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

但出现以下错误:

org.openqa.selenium.remote.ErrorHandler$UnknownServerException:元素当前不可见,因此可能无法与之交互`

4

1 回答 1

0

您可以尝试以下方法:

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则执行下一行,否则跳过它。

于 2016-10-14T08:53:27.723 回答