我遇到NoSuchElementException的超时时间问题,默认情况下似乎是30秒,我想缩短它。所以我写了这样的话:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
element.click();
我收到了这条消息:
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for element to be
clickable: By.id: someid
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"id","selector":"someid"}
Command duration or timeout: 30.03 seconds
所以第一条消息是我希望WebDriverWait覆盖NoSuchElementException超时,但我仍然得到整整30秒。无论如何,摆脱这个的方法是什么?
答案 0 :(得分:3)
尝试其中一些:
driver.manage().timeouts().implicitlyWait()
driver.manage().timeouts().setScriptTimeout()
答案 1 :(得分:2)
使用Java在Selenium WebDriver中等待10秒: For Implicit wait:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
明确等待:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someID")));