这是显式等待的示例代码:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath-here")));
我想将 WebElement 作为方法中的参数传递,并等待直到找到该 WebElement:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(MyWebElement));
我不确定这样的选项是否已经存在,并且可以以不同的方式完成,就像在我的例子中,当我传递 WebElement 代替 By.xpath("")
这不是正确的方法。
最佳答案
您需要使用 visibilityOf
预期条件。
代码如下:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(MyWebElement));
希望对你有帮助!
关于java - 如何编写显式等待,直到找到特定的 WebElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54482629/