-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathTestExplicitWait.java
52 lines (46 loc) · 1.82 KB
/
TestExplicitWait.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.SeleniumPractice;
import java.time.Duration;
import java.util.Set;
import java.util.function.Function;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.github.bonigarcia.wdm.WebDriverManager;
/**
* @author Yadagiri Reddy
* Explicit Wait in Selenium WebDriver?
*/
public class TestExplicitWait {
public static void main(String[] args) throws Exception {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1000, 1000));
WebDriverWait wait = new WebDriverWait(driver, 10);
// FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
// wait.withTimeout(Duration.ofSeconds(10));
driver.get("https://testproject.io/");
String parentWindow = driver.getWindowHandle();
driver.findElement(By.linkText("Login")).click();
Set<String> windowHandles = driver.getWindowHandles();
for (String windowHandle : windowHandles) {
if(!windowHandle.equals(parentWindow)) {
driver.switchTo().window(windowHandle);
// Function<WebDriver, Boolean> f = new Function<WebDriver, Boolean>() {
// @Override
// public Boolean apply(WebDriver webDriver) {
// return webDriver.findElement(By.id("username")).isDisplayed();
// }
// };
// wait.until(f);
// wait.until(d->d.findElement(By.id("username")).isDisplayed());
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
driver.findElement(By.id("username")).sendKeys("HYR Tutorials");
}
}
}
}