Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

In selenium we have  Implicit and Explicit Waits: 

Dynamic wait : Element is found in 2 seconds it will skip the 8 seconds

OR                     Element is found in 4 seconds it will skip the 6 seconds

Static wait - Thread.sleep(10000) // 10 secons it will halt the program


Implicitly Wait : is a dyanmic wait 

  1. //implicitlyWait is a global wait
  2. it is applied to all the elements by default
  3. Implicitly wait only applies for web elements(it will never wait for NonWeb Elements
  4. EX: browsers title, alerts,URL,browserwindow,URL)

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

driver.manage().timeouts().implicitlyWait(Duration.ofMinutes(0));


Element is found in 2 seconds it will skip the 8 seconds

//implicitlyWait by default it will wait 10 seconds ,

//if element found for 2 seconds then it will take only 2 seconds

only ,8 seconds will be ignored

//if we have 5 elements it will wait 5*10=50 seconds

driver.findElement(By.id("Form_getForm_Name")).sendKeys("Hello");


ExplicitlyWait : we can apply this to only the element that is taking more time to load on the page ,so that it will wait for specified time .


WebDriverWait : 


By ph = By.id("Form_getForm_Contact");

WebDriverWait waita = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement phoe = waita.until(ExpectedConditions.presenceOfElementLocated(ph));

phoe.sendKeys("5467891254");


ExplicitlyWait  can perform waits on nonWebElements

  1. PageTitle:
  2. URL
  3. Alert
  4. Window

    WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
  • wait.until(ExpectedConditions.urlContains("30-day-free-trial"));
  • wait.until(ExpectedConditions.urlToBe("https:");
  • wait.until(ExpectedConditions.titleIs("30-Day Advanced Free Trial | OrangeHRM");
  • wait.until(ExpectedConditions.titleContains("30-Day"));
  • wait.until(ExpectedConditions.presenceOfElementLocated(sele))
  • wait.until(ExpectedConditions.presenceOfElementLocated(sele));
  • wait.until(ExpectedConditions.alertIsPresent(sele));
  • wait.until(ExpectedConditions.elementToBeClickable(sele));
  • wait.until(ExpectedConditions.elementToBeSelected(sele));
  • wait.until(Expec
  • wait.until(ExpectedConditions.numberOfWindowsToBe(sele));
  • wait.until(ExpectedConditions.visibilityOf(sele));

Pooling Time/Interval:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10),Duration.ofSeconds(2));

Params: below

* 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.


*/

FluentWait<WebDriver> wait=new FluentWait<WebDriver>(driver).withTimeout(Duration.ofSeconds(10)).pollingEvery(Duration.ofSeconds(2));

WebElement g= wait.until(ExpectedConditions.elementToBeClickable(aa));


PageLoadTimeOut - Page will wait for max time, if not completed it will throws an exception



WaitforPageLoading :document.readyState


JS :   document.readystateate







Comments

Popular posts from this blog

A Interview Questions- selenium