Switch between browser tabs using Selenium WebDriver with Java

后端 未结 3 808
无人及你
无人及你 2020-12-20 18:53

I need to switch between the browser tabs, used the following code,

driver.findElement(By.cssSelector(\"body\")).sendKeys(Keys.CONTROL +\"\\t\");
         


        
3条回答
  •  无人及你
    2020-12-20 19:33

    Switching between browser window is different from switching b/w tabs.

    In some browser windowhandler command may work but it wont work in all browser.

    Here is the solution to navigate b/w tabs

    for navigating left to right side:

    Actions action= new Actions(driver);
    action.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).build().perform();
    

    For navigating right to left :

    Actions action= new Actions(driver);
    action.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).build().perform();
    

提交回复
热议问题