package demopackage;
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 WindowsExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Work\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/intl/en-GB/gmail/about/#");
System.out.println(driver.getTitle());
driver.findElement(By.xpath("//ul[@class='h-c-header__cta-list header__nav--ltr']//a[contains(@class,'h-c-header__nav-li-link')][contains(text(),'Sign in')]")).click();
Set ids = driver.getWindowHandles();
Iterator it = ids.iterator();
String parentid = it.next();
String childid = it.next();
driver.switchTo().window(childid);
System.out.println(driver.getTitle());
driver.switchTo().window(parentid);
System.out.println(driver.getTitle());
driver.quit();
}
}
HOW TO HANDLE MULTIPLE WINDOW HANDLES.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment