Java 如何让webdriver等待,它使用什么语句?

Java 如何让webdriver等待,它使用什么语句?,java,selenium,webdriver,Java,Selenium,Webdriver,仅第一行就让webdriver等待10秒吗?还是两者都要 WebDriverWait wait = new WebDriverWait(firefoxDriver,10); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID))); 我不明白是什么陈述让司机等待?这个陈述够了吗 WebDriverWait wait = new WebDriverWait(firefoxDriver,10);

仅第一行就让webdriver等待10秒吗?还是两者都要

 WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));
我不明白是什么陈述让司机等待?这个陈述够了吗

WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
Wait将忽略默认情况下在“until”条件下遇到(抛出)的NotFoundException实例,并立即传播所有其他实例


您可以通过调用ignore(exceptions to add)方法向ignore列表添加更多内容。

据我所知,Selenium提供了三种不同的等待机制<代码>显式,
隐式
流畅
。看见您提到的是显式的。显式等待意味着等待元素满足您告诉
WebDriver
的特定条件。例如元素的可见性(您正在使用的)、元素存在等。
org.openqa.selenium.support.ui
中有一个名为
ExpectedConditions
的类,它有大量的成员,为等待元素提供了不同的机制。有关完整列表,请参阅

回到你的问题:
WebDriverWait wait=newwebdriverwait(firefoxDriver,10)
仅定义等待和WebDriver应等待的长度,以满足您提供的条件(在第二行中) 实际的等待发生
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID))
WebDriver
尝试查找与
xpathID
匹配的元素,该元素在页面上可见,在
10s
之后抛出异常。如果
WebDriver
10s
之前找到目标元素,它将不会等待
10s
并向前移动。

对我的问题最好的解释!
WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));