Switch tabs using Selenium WebDriver with Java

前端 未结 21 1586
野性不改
野性不改 2020-11-22 12:09

Using Selenium WebDriver with JAVA. I am trying to automate a functionality where I have to open a new tab do some operations there and come back to previous tab (Parent). I

21条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 12:51

        psdbComponent.clickDocumentLink();
        ArrayList tabs2 = new ArrayList (driver.getWindowHandles());
        driver.switchTo().window(tabs2.get(1));
        driver.close();
        driver.switchTo().window(tabs2.get(0));
    

    This code perfectly worked for me. Try it out. You always need to switch your driver to new tab, before you want to do something on new tab.

提交回复
热议问题