Selenium Managing Multiple Tabs

in #python-dev5 years ago
WebDriver driver = new FirefoxDriver(); 
driver.manage().window().maximize(); 
driver.get("URL");
 
String newWindow = driver.getWindowHandle();
 
driver.findElement(By.cssSelector(“body”)).sendKeys(Keys.CONTROL+”t”);
driver.get("Second URL");
 
//Perform whatever actions you want done on the secondary tab, let’s pretend we’re logging in somewhere
 
driver.findElementById(“ID”).sendKeys(“username”);
driver.findElementById(“ID”).sendKeys(“password”);
driver.findElementById(“submit”).click();
 
driver.switchTo().window(mainWindow);
 
//Perform whatever actions you want done on the main tab, we’ll click a button
driver.findElementById(“button”).click();
 
# Close current tab
driver.findElement(By.cssSelector(“body”)).sendKeys(Keys.CONTROL + 'w');
 
driver.close();
Sort:  

this is a good instruct ion, so it can be used to switch and automate different web pages