Selenium webdriver 是否可以为WebDriverWait定义超时条件?

Selenium webdriver 是否可以为WebDriverWait定义超时条件?,selenium-webdriver,webdriver,Selenium Webdriver,Webdriver,在时间单位过期(WebDriverWait超时)时,是否可以包含条件(例如单击按钮/driver.navigate.back()) 例如: 就以下陈述而言— WebDriverWait wait60=新的WebDriverWait(驱动程序,60); wait60.until(ExpectedConditions.elementtobelickable(driver.findElement(By.locator)) 如果ElementTobelickable在60秒内没有加载到网页上,我希望执行

在时间单位过期(WebDriverWait超时)时,是否可以包含条件(例如单击按钮/driver.navigate.back())

例如: 就以下陈述而言— WebDriverWait wait60=新的WebDriverWait(驱动程序,60); wait60.until(ExpectedConditions.elementtobelickable(driver.findElement(By.locator))


如果ElementTobelickable在60秒内没有加载到网页上,我希望执行语句driver.navigate.back()。有没有办法定义这种类型的语句(比如在类级别)以便所有wait60.until条件在超时时产生相同的已定义语句

我认为这不包括在
WebDriverWait
功能中。我可能会使用try-catch异常处理,当您捕获
timeoutException
时,调用
driver.navigate.back()


您可以创建一个执行此操作的方法,并随时调用它。

将其放入一个try-catch块中,如下所示:

try{
    WebDriverWait wait60 = new WebDriverWait(driver, 60);
    wait60.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.locator)));
}catch(Exception e){
    System.out.println("Element not found in due time.  "+e.getMessage);
    driver.navigate().back();
}

若在适当的时间内找不到该元素,将抛出TimeoutException,随后将在catch块中处理它。此外,在此之后,浏览器将被导航回

您不想使用try-catch?TimeoutException而不是nosuchelementExection。我编辑了这个。