In my automation script i used explicit wait for handling wait time
wait = new WebDriverWait(driver, Duration.ofSeconds(45000));
public WebElement waitVisibility(By by) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
Now sometimes I got an error element not found Because some popup messages appear for a very short time.
error is like (tried for 40 second(s) with 500 milliseconds interval)
Here my question is how to decrese the pulling time 500 millisecond to 200 millisecond
CodePudding user response:
As you can see Selenium
WebDriverWait
is set by default to poll the DOM every 500 milliseconds. We can override this setting with the use of pollingEvery
method.
This can be done as following:
public WebElement waitVisibility(By by) {
WebDriverWait wait = new WebDriverWait(driver, 40);
wait.pollingEvery(200, TimeUnit.MILLISECONDS);
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
CodePudding user response:
To configure the duration in milliseconds to sleep between polls you can use the following constructor of WebDriverWait:
public WebDriverWait(WebDriver driver, java.time.Duration timeout, java.time.Duration sleep)
Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).
Parameters:
- driver - The WebDriver instance to pass to the expected conditions
- timeout - The timeout in seconds when an expectation is called
- sleep - The duration in milliseconds to sleep between polls.
Implementation:
wait = new WebDriverWait(driver, Duration.ofSeconds(45000), Duration.ofMilliSeconds(200));
public WebElement waitVisibility(By by) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}