如何让 webdriver 等待以及它的语句是什么?

How to make webdriver wait and what statement does it?

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

 WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));

我对什么语句让驱动程序等待感到困惑?这个语句是否足够?

WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));

Wait 将忽略 'until' 条件下默认遇到(抛出)的 NotFoundException 实例,并立即传播所有其他实例。

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

据我所知,Selenium 提供了三种不同的等待机制。 ExplicitImplicitFluent。有关完整列表,请参阅 this. The one you have mentioned is Explicit. Explicit wait is meant to wait for element to meet certain condition you tell the WebDriver. Such as element's visibility(the one you are using),element exists etc. There is a class in org.openqa.selenium.support.ui named ExpectedConditions that has good number of members to provide different mechanism for waiting for the element.See here

回到你的问题: WebDriverWait wait = new WebDriverWait(firefoxDriver,10); 只定义了等待的长度 WebDriver 应该等待满足你提供的 条件(在第二行。) 实际等待发生 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));WebDriver 试图找到与 xpathID 匹配的元素,它在页面上可见,在 10s 之后它抛出异常。如果 WebDriver10s 之前找到目标元素,它将不会等待 10s 并继续前进。