In this post, we will see Explicit Wait in Selenium Webdriver Java | Selenium Explicit Wait | Implicit Wait vs WebDriverWait
Program Code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class ExplicitWait {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://in.bookmyshow.com/explore/movies-pune");
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
WebDriverWait w =new WebDriverWait(driver, Duration.ofSeconds(5));
driver.findElement(By.xpath("(//div[text()='Marathi'])[3]")).click();
w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='Chandramukhi (Marathi)']")));
driver.findElement(By.xpath("//img[@alt='Chandramukhi (Marathi)']")).click();
driver.navigate().back();
driver.findElement(By.xpath("(//div[text()='English'])[3]")).click();
w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='Top Gun: Maverick']")));
driver.findElement(By.xpath("//img[@alt='Top Gun: Maverick']")).click();
}
}
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=f58wLYRoYTc&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=17
No comments:
Post a Comment