Switch tabs using Selenium WebDriver with Java

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

    This will work for the MacOS for Firefox and Chrome:

    // opens the default browser tab with the first webpage
    driver.get("the url 1");
    thread.sleep(2000);
    
    // opens the second tab
    driver.findElement(By.cssSelector("Body")).sendKeys(Keys.COMMAND + "t");
    driver.get("the url 2");
    Thread.sleep(2000);
    
    // comes back to the first tab
    driver.findElement(By.cssSelector("Body")).sendKeys(Keys.COMMAND, Keys.SHIFT, "{");
    

提交回复
热议问题