-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowsAssgn.java
36 lines (22 loc) · 1.01 KB
/
WindowsAssgn.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
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class WindowsAssgn {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/tanvi/Documents/automation_testing/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://the-internet.herokuapp.com/");
driver.findElement(By.xpath("//a[contains(text(),'Multiple Windows')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Click Here')]")).click();
Set<String> windows = driver.getWindowHandles();
Iterator<String> it = windows.iterator();
String parentId = it.next();
String childId = it.next();
driver.switchTo().window(childId);
System.out.println(driver.findElement(By.cssSelector(".example h3")).getText());
driver.switchTo().window(parentId);
System.out.println(driver.findElement(By.cssSelector(".example h3")).getText());
}
}