Waiting Mechanism
Waiting Mechanism
Waiting Mechanism
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
driver.get("https://iamsandesh23.github.io/selenium.github.io/");
driver.manage().window().maximize();
driver.findElement(By.className("dropbtn")).click();
driver.findElement(By.linkText("Facebook")).click();
driver.get("https://iamsandesh23.github.io/selenium.github.io/");
driver.manage().window().maximize();
driver.findElement(By.className("dropbtn")).click();
Thread.sleep(3000);
driver.findElement(By.linkText("Facebook")).click();
}
}
Implicit Wait - Instead of halting the program till the specified time is
reached, Implicit wait will wait for all the web elements dynamically (i.e.
Global wait)
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
driver.manage().timeouts().implicitlyWait(5,
TimeUnit.SECONDS);
driver.get("https://iamsandesh23.github.io/selenium.github.io/");
driver.manage().window().maximize();
driver.findElement(By.className("dropbtn")).click();
driver.findElement(By.linkText("Facebook")).click();
}
Explicit Wait - Instead of waiting for all the statements in the program,
Explicit wait will wait only for the specific web element
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Demo {
driver.get("https://iamsandesh23.github.io/selenium.github.io/");
driver.manage().window().maximize();
driver.findElement(By.className("dropbtn")).click();
WebElement element =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.l
inkText("Facebook")));
element.click();
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Demo {
driver.get("https://iamsandesh23.github.io/selenium.github.io/");
driver.manage().window().maximize();
driver.findElement(By.className("dropbtn")).click();
WebElement element =
wait.until(ExpectedConditions.elementToBeClickable(By.linkT
ext("Facebook")));
element.click();