如何切换selenium webdriver中的选项卡

时间:2017-10-11 03:57:04

标签: selenium-webdriver

我想将标签从一个标签切换到另一个标签,然后需要切换回上一个标签。

所以,请指导我。

1 个答案:

答案 0 :(得分:0)

 String winHandleBefore = driver.getWindowHandle();

    // Perform the click operation that opens new window

    driver.findElement(By.xpath("yourElement").click());
    // Switch to new window opened
    for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
    }

    // Perform the actions on new window

    // Close the new window, if that window no more required
    driver.close();

    // Switch back to original browser (first window)
    driver.switchTo().window(winHandleBefore);