Switch tabs using Selenium WebDriver with Java

前端 未结 21 1189
野性不改
野性不改 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:57

    String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL, Keys.RETURN);
        WebElement e = driver.findElement(By
                .xpath("html/body/header/div/div[1]/nav/a"));
    e.sendKeys(selectLinkOpeninNewTab);//to open the link in a current page in to the browsers new tab
    
        e.sendKeys(Keys.CONTROL + "\t");//to move focus to next tab in same browser
        try {
            Thread.sleep(8000);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        //to wait some time in that tab
        e.sendKeys(Keys.CONTROL + "\t");//to switch the focus to old tab again
    

    Hope it helps to you..

提交回复
热议问题