【问题标题】:Selenium Explicit Wait(WebDriverWait) is not working with Type WebElementSelenium Explicit Wait(WebDriverWait) 不适用于 WebElement 类型
【发布时间】:2016-03-19 04:46:16
【问题描述】:
driver= new InternetExplorerDriver(cap);
driver.get("http://Myurl.com"); 
WebDriverWait wait= new WebDriverWait(driver,10);   

案例1:wait.until(ExpectedConditions.elementToBeClickable(By.id("Tesr"))); 对于上面的代码驱动程序在抛出异常之前等待大约 10 秒但是如果使用下面的代码将 WebElement 传递给函数“elementToBeClickable”,它会在大约 500 毫秒后抛出异常

案例2:wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("Tesr"))));

请任何人告诉我为什么案例 2 驱动程序没有等到超时值。

【问题讨论】:

  • 我能知道你发现了哪个异常吗?

标签: selenium


【解决方案1】:

当您在显式等待函数中使用driver.findElement 时,driver.findElement 优先执行。这只是意味着,WebDriver 尝试查找元素并将找到的元素提供给 ExpectedCondiions.elementToBeClickable 方法。因此,在尝试查找元素时,仅考虑隐式等待(全局等待),因为您的情况下的隐式等待为 500 毫秒,并且未找到元素 NoSuchElementException 被抛出。

不,如果异常是从隐式等待中引发的,你会得到TimeOutException。相反,您会得到来自driver.findElement 方法的NoSuchElementException

【讨论】:

  • 感谢您回答我的问题。
  • 如果您认为正确,请接受可以关闭问题的答案日期。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
  • 2015-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多