Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium.setTimeout未等待指定的时间_Java_Selenium - Fatal编程技术网

Java Selenium.setTimeout未等待指定的时间

Java Selenium.setTimeout未等待指定的时间,java,selenium,Java,Selenium,我们必须持续监视URL以检查其可用性。我已经使用selenium进行了模拟。下面粘贴的是一段代码 driver = new InternetExplorerDriver(); selenium = new WebDriverBackedSelenium(driver, mainUrl); selenium.setTimeout("90000"); selenium.open(mainUrl); 但是,即使URL在90000毫秒内未打开,selenium.timeout也不起作用。如何修复此问题

我们必须持续监视URL以检查其可用性。我已经使用selenium进行了模拟。下面粘贴的是一段代码

driver = new InternetExplorerDriver();
selenium = new WebDriverBackedSelenium(driver, mainUrl);
selenium.setTimeout("90000");
selenium.open(mainUrl);
但是,即使URL在90000毫秒内未打开,
selenium.timeout
也不起作用。如何修复此问题?

尝试使用Thread.sleep()

如果要检查可用性,请尝试使用fluentWait:

 public WebElement fluentWait(final By locator){
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(30, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

        WebElement foo = wait.until(
new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                        return driver.findElement(locator);
                }
                }
);
                           return  foo;              }     ;
publicwebelement fluentWait(最终由定位器确定){
等待等待=新建FluentWait(驱动程序)
.带超时(30,时间单位。秒)
.轮询间隔(5,时间单位。秒)
.忽略(NoSuchElementException.class);
WebElement foo=wait.until(
新函数(){
公共WebElement应用(WebDriver){
返回驱动程序findElement(定位器);
}
}
);
返回foo;};
Wait接口的一种实现,可以动态配置其超时和轮询间隔。 每个FluentWait实例定义等待条件的最长时间,以及检查条件的频率。此外,用户可以将等待配置为在等待时忽略特定类型的异常,例如在搜索页面上的元素时忽略NoTouchElementExceptions

希望这对您有所帮助)

您也可以使用:

driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
根据,示例如下所示:

driver = new InternetExplorerDriver();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
selenium.open(mainUrl);

最新支持
this.driver.manage().setTimeout({…})
driver = new InternetExplorerDriver();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
selenium.open(mainUrl);