Selenium web server polling time

I am looking forward to a detailed explanation of selenium webdriver polling timing in Selenium.

As I know the wait command will wait 40 seconds until a specific element receives a clickable

  public void CreateSalesOrder(){
        WebDriverWait wait = new WebDriverWait(driver, 40);
        wait.until(ExpectedConditions.elementToBeClickable(btnNewSalesOrser));
            btnNewSalesOrser.click(); 
    }

      

In the second code snippet, I added the Poll command.

   public void CreateSalesOrder(){
        WebDriverWait wait = new WebDriverWait(driver, 40);
        wait.pollingEvery(2, TimeUnit.SECONDS);
        wait.until(ExpectedConditions.elementToBeClickable(btnNewSalesOrser));
        btnNewSalesOrser.click();
    }

      

What is the use of polling time?

+3


source to share


3 answers


If we did not mark any polling times, selenium will take the default polling times as 500 milliseconds. ie., the script will check for an excluded condition for a web element in a web page every 500 milliseconds. Your first piece of code works with this.

We use pollingEvery to override the default polling time. In the example below (your second code snippet), the script checks the expected state every 2 seconds, not 500 milliseconds.

public void CreateSalesOrder()
{
    WebDriverWait wait = new WebDriverWait(driver, 40);
    wait.pollingEvery(2, TimeUnit.SECONDS);
    wait.until(ExpectedConditions.elementToBeClickable(btnNewSalesOrser));
    btnNewSalesOrser.click();
}

      



This polling rate can actually help reduce CPU overhead. Refer to this javadoc for more information on pollingEvery .

Hope this helps you. Thank.

+5


source


Using WebDriverWait wait = new WebDriverWait(driver, 40);

, the driver will wait a maximum of 40 seconds until the condition is met.

Usage wait.pollingEvery(2, TimeUnit.SECONDS);

indicates that the driver will perform a check (to make sure the condition is met) every 2 seconds until the condition is met.


This adds up to your driver checking every 2 seconds for a period of 40 seconds .




You can also specify the polling interval as a shortcut in the Constructor :

WebDriverWait wait = new WebDriverWait(driver, 40, TimeUnit.SECONDS.toMillis(2));

      

+1


source


To understand the explanation, you need to understand the polling time for Explicit Wait.

WebDriverWait wait = new WebDriverWait (driver, 40);

It waits up to 40 seconds before throwing a TimeoutException if it does not find an item to return within 40 seconds. WebDriverWait by default calls ExpectedCondition every 500 milliseconds until it returns successfully, so the default polling time for ExplicitWait is 500 milliseconds.

wait.pollingEvery (2, TimeUnit.SECONDS);

In this case, the polling time is 2 seconds, since the expected condition will not be checked every 500 milliseconds, it must be checked after 2 seconds until specific items are available.

0


source







All Articles