I need to open two different urls in two different tabs and then I need to keep switching between them as the flow of my application is as such.
I have included some code for opening different urls along with window handling code but it doesn't seem to be working fine as first tab would open gmail.com and then yahoo.com and second tab then opens up yahoo.com. I need to have tab1 as gmail.com and tab2 as yahoo.com and also I need to keep on switching to them anytime I want to in between the script.
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.gmail.com");
Thread.sleep(3000);
((JavascriptExecutor)driver).executeScript("window.open()");
handlewindlow("Untitled"); //Untitled is title for new tab
}
static void handlewindlow(String title) {
Set<String>setHandleValues=driver.getWindowHandles();
Iterator<String> iteHandleValues=setHandleValues.iterator();
while(iteHandleValues.hasNext()==true){
String handleValue=iteHandleValues.next();
driver.switchTo().window(handleValue);
CurrentUrl=driver.getCurrentUrl();
String CurrentUrl=driver.getTitle();
driver.get("https://www.yahoo.com");
}
}