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 FluentWait默认超时为零_Java_Selenium - Fatal编程技术网

Java FluentWait默认超时为零

Java FluentWait默认超时为零,java,selenium,Java,Selenium,当我们没有像下面那样指定时,FluentWait的默认超时是多少,但我知道默认轮询是500毫秒 FluentWait<WebDriver> wait=new FluentWait<WebDriver>(dr) //.withTimeout(Duration.ofSeconds(20)) //.pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElemen

当我们没有像下面那样指定时,FluentWait的默认超时是多少,但我知道默认轮询是500毫秒

         FluentWait<WebDriver> wait=new FluentWait<WebDriver>(dr)
        //.withTimeout(Duration.ofSeconds(20))
        //.pollingEvery(Duration.ofSeconds(2))
        .ignoring(NoSuchElementException.class);
这是否意味着我们的默认最大超时为0秒。
当我通过时,它说默认的睡眠超时为

每个FluentWait实例定义了等待条件的最大时间量,默认为500毫秒。您已经在文档中提到过,也可以从

超时异常日志
线程“main”org.openqa.selenium.TimeoutException中的异常:(以500毫秒的间隔尝试0秒)
因为这就是控制台中记录异常的方式,即withTimeout以秒为单位进行计算,以毫秒为单位进行轮询

想象

尝试1:

wait=new FluentWait<>(driver)
                .withTimeout(Duration.ofMillis(500))
                .pollingEvery(Duration.ofSeconds(2))
                .ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//someElementLocator")));
尝试2:

wait=new FluentWait<>(driver)
                .withTimeout(Duration.ofMillis(1500))
                .pollingEvery(Duration.ofSeconds(2))
                .ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//someElementLocator")));
这确认了等待超时和轮询间隔的评估方式,然后可能四舍五入到最低值(500毫秒->0秒,1500毫秒->1秒),并记录到控制台


希望这一切都清楚

所以最大超时和轮询都有500毫秒的默认值?@J_Coder是的!只需注释掉
.pollingEvery(持续时间为秒(2))
并在控制台中查看异常,应
以500毫秒的间隔尝试0秒
wait=new FluentWait<>(driver)
                .withTimeout(Duration.ofMillis(500))
                .pollingEvery(Duration.ofSeconds(2))
                .ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//someElementLocator")));
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //someElementLocator (tried for 0 second(s) with 2000 milliseconds interval)
wait=new FluentWait<>(driver)
                .withTimeout(Duration.ofMillis(1500))
                .pollingEvery(Duration.ofSeconds(2))
                .ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//someElementLocator")));
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //someElementLocator (tried for 1 second(s) with 2000 milliseconds interval)