WebDriver.getWindowHandle() method

后端 未结 5 1243
春和景丽
春和景丽 2020-12-18 07:49

I\'m new to Selenium learning. WebDriver.getWindowHandle() documentation is not very clear to me and the example is not working as given in the book, so I thought of confirm

5条回答
  •  误落风尘
    2020-12-18 08:07

    I have used this code for my project

    String oldTab = driver.getWindowHandle();
    
    public static void switchingToNewTabUsingid(WebDriver driver,WebDriverWait wait,String id,String oldTab)
        {
            wait.until(ExpectedConditions.elementToBeClickable(By.id(id)));
            driver.findElement(By.id(id)).click();
            ArrayList newTab = new ArrayList(driver.getWindowHandles());
            newTab.remove(oldTab);
            driver.switchTo().window(newTab.get(0));
        }
    

    //Perfrom Opeartion here on switched tab

    public static void comingBackToOldTab(WebDriver driver,String oldTab)
        {
            driver.close();
            driver.switchTo().window(oldTab);
        }
    

提交回复
热议问题