-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserPopUpHandle.java
More file actions
35 lines (27 loc) · 941 Bytes
/
Copy pathBrowserPopUpHandle.java
File metadata and controls
35 lines (27 loc) · 941 Bytes
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
package basicselenium;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class BrowserPopUpHandle {
public static void main(String[] args) throws InterruptedException {
String url="http://www.popuptest.com/goodpopups.html";
WebDriver driver=SetupClass.setupMethod(url);
WebElement link1=driver.findElement(By.xpath("/html/body/table[2]/tbody/tr/td/font/b/a[1]"));
link1.click();
Thread.sleep(10000);
Set<String> handler=driver.getWindowHandles();
Iterator<String> it=handler.iterator();
String parentWindow=it.next();
String childWindow=it.next();
driver.switchTo().window(childWindow);
System.out.println(driver.getTitle());
Thread.sleep(10000);
driver.close();
driver.switchTo().window(parentWindow);
System.out.println(driver.getTitle());
Thread.sleep(10000);
driver.close();
}
}