selenium few WebDrivers one window [JAVA]

I have problem with selenium JAVA. I have something like this:


WebDrvier driver1 = new FirefoxDriver();

WebDrvier driver2 = new FirefoxDriver();


How to open driver1 and driver2 in one window and two tabs?

thanks in advance for your help

Default Asked on August 3, 2015 in Selenium WebDriver.
Add Comment
  • 2 Answer(s)

    Hi Chester,
    You can use robot class to open new tab. The example code is mentioned below.

    public class multiple {
    public static void main(String[] args) throws InterruptedException {
    //To open Firefox browser
    WebDriver driver=new FirefoxDriver();
    //To maximize the browser
    driver.manage().window().maximize();
    driver.get(“https://www.google.co.in/?gfe_rd=cr&ei=GNvBVcG2JPDI8AeIoY2oBA&gws_rd=ssl”);
    driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
    //robot class
    try {
    Robot robot=new Robot();
    //To open the new tab
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_T);
    } catch (AWTException e) {
    e.printStackTrace();
    }
    Thread.sleep(5000);
    driver.get(“http://currentaffairs.gktoday.in/”);
    }
    }

    Train Answered on August 5, 2015.
    Add Comment

    I have two WebDrivers. This code works if there one webdriver.

    Default Answered on August 6, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.