Switch tabs using Selenium WebDriver with Java

前端 未结 21 1454
野性不改
野性不改 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 13:03

    Work around

    Assumption : By Clicking something on your web page leads to open a new tab.

    Use below logic to switch to second tab.

    new Actions(driver).sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(driver.findElement(By.tagName("html")),Keys.NUMPAD2).build().perform();
    

    In the same manner you can switch back to first tab again.

    new Actions(driver).sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(driver.findElement(By.tagName("html")),Keys.NUMPAD1).build().perform();
    

提交回复
热议问题