I’m automating script using java using selenium webdriver. But i’m getting stuck on switch to new tab and pass url in new tab as well using chrome browser.Can you provide be solution for that.

  • 2 Answer(s)

    Hi Surabhi,

    This is an example code. You can customize it according to your use.

    // Initialize driver
    WebDriver driver = new FirefoxDriver();

    //Maximize browser window

    //Go to URL

    //Set timeout
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Open new tab  – May be you are stuck here
    driver.findElement(By.cssSelector(“body”)).sendKeys(Keys.CONTROL + “t”);

    //Go to URL

    //Set new tab timeout
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Do some operation

    Vishal S

    Doctor Answered on May 25, 2016.
    WebDriver driver = new ChromeDriver(); // for chrome driver
    on May 25, 2016.
    Add Comment

    Hi ,

    u need to import the chrome driver and path to use the chrome driver browser.
    here are the code of that.
    System.setProperty(“webdriver.chrome.driver”, “<path where chromdriver.exe stored.>”);

    and then create the instance of chromedriver class.

    Train Answered on May 31, 2016.
    Add Comment
  • Your Answer

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