Monday, January 8, 2018

Multiple Tags Simplified


package com.examples;

import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Multiple_Tabs_03 {

public static void main(String[] args) throws InterruptedException {
System.setProperty("Webdriver.chrome.driver", "chromedriver");
WebDriver wd = new ChromeDriver();
int i = 2;
if (i == 2) {
wd.get("https://www.w3schools.com/jsref/met_win_open.asp");

wd.findElement(By.xpath(".//*[@id='main']/div[2]/a")).click();
Set<String> str = wd.getWindowHandles();
for (String st : str) {
wd.switchTo().window(st);
System.out.println(wd.getTitle());
Thread.sleep(5000);
wd.close();

}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(wd.getTitle());
}
}

}

No comments:

Post a Comment