gpt4 book ai didi

java - WebDriver 中的隐式等待不会暂停执行

转载 作者:行者123 更新时间:2023-12-01 20:15:05 26 4
gpt4 key购买 nike

我初始化并设置我的驱动程序如下:

System.setProperty("webdriver.firefox.bin", Vars.FFPATH);
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.navigate().to(siteurl);
driver.manage().timeouts().implicitlyWait(30, SECONDS);

我认为,在执行其余代码之前应该等待 30 秒。不行,没有等待时间,执行只需8秒。我尝试使用 FluentWait 通过等待 elemnt 可点击来获得一些等待时间。

FluentWait<WebDriver> wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(webpage.linput));

错误消息:

java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:102) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:71) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:45)

我使用Logger检查了变量webpage.linput,它有一个有效值,即给定元素的xpath,因此它不为空。此处创建的变量:

By linput = By.xpath("//*[@id=\"formA\"]/p[1]/label");

版本:

WebDriver 3.5.2
GeckoDriver 0.18.0
Firefox 55.0.3

最佳答案

有几件事。

隐式等待

不应该

driver.navigate().to(siteurl);
driver.manage().timeouts().implicitlyWait(30, SECONDS);

应该是

driver.manage().timeouts().implicitlyWait(30, SECONDS);
driver.navigate().to(siteurl);

此外,隐式等待不会暂停执行,它只是增加每个操作(即 findElement、单击)的超时

pageLoadTiemout:

此外,如果您想增加页面加载的超时时间,隐式等待也无济于事。你应该使用pageLoadTiemout

检查以下页面。 https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html

对于第二个问题

用户 webdriver 等待而不是流畅等待。

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(webpage.linput));

如果您只想暂停执行

使用Thread.sleep()方法。

关于java - WebDriver 中的隐式等待不会暂停执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45956708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com