Selenium switchTo () toggle window
Public void swithWindowTest () {driver.findElement (By.className ("open")) .click (); String winHandleBefore = driver.getWindowHandle () / / get the handle of the current window for (String winHandle: driver.getWindowHandles ()) {/ / traverse the handle of all windows if (driver.switchTo (). Window (winHandle). GetTitle (). Contains ("Baidu")) {driver.switchTo () .window (winHandle) / / switch to break;}} driver.findElement (By.id ("kw")) .sendKeys ("selenium baidu") in the window containing "Baidu" in title; / / enter selenium baidu driver.findElement (By.id ("su")) .click () Driver.switchTo () .window (winHandleBefore); / / switch to the previous window driver.findElement (By.id ("user")) .sendKeys ("selenium Demo"); / / enter selenium demo}