你看对了。@JimEvans在讨论中明确指出:
问题的部分原因是隐式等待通常(但可能并非总是如此!)在WebDriver系统的“远程”侧实现。这意味着它们被“嵌入”到IEDriverServer.exe,chromedriver.exe,安装在匿名Firefox配置文件中的WebDriver
Firefox扩展以及Java远程WebDriver服务器(selenium-server-
standalone.jar)。显式等待专门在“本地”语言绑定中实现。使用RemoteWebDriver时,事情变得更加复杂,因为您可能同时使用了系统的本地端和远程端。
因此,与元素交互时,显式等待是任务。
现在,按照WebDriverWait的构造函数:
public WebDriverWait(WebDriver driver, long timeOutInSeconds)
:Wait将NotFoundException
默认忽略在“直到”条件下遇到(抛出)的实例,并立即传播所有其他实例。您可以通过调用ignoring(要添加的例外)将更多内容添加到忽略列表。WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)
:Wait将NotFoundException
默认忽略在“直到”条件下遇到(抛出)的实例,并立即传播所有其他实例。您可以通过调用ignoring(要添加的例外)将更多内容添加到忽略列表。
因此,
WebDriverWait()默认情况下会忽略NotFoundException,并且直接已知的子类为:
NoalertPresentException
NoSuchContextException
NoSuchcookieException
NoSuchElementException
NoSuchframeException
NoSuchWindowException
从WebDriverWait.java的源代码中:
因此,在使用 WebDriverWait时, 您将不会遇到 NoSuchElementException 。如果在
WebDriverWait 到期之前没有返回所需的元素,您将面临timeoutException 。



