Search
  • 9to5 Technologies

How to Open second URL in new Tab of a Browser Using Selenium WebDriver with Java.

First open url in First Tab and open second tab by Pressing “Control+t” from keyboard.


Now disable the first Tab and insert second url in second Tab.


You can use Following code:


CODE:

public class basics {

public static void main(String[] args) throws AWTException, InterruptedException {

// TODO Auto-generated method stub

WebDriver driver;

System.setProperty(“webdriver.chrome.driver”, “D: \\Tools\\ BrowserDriver\\ chromedriver.exe”);

driver = new ChromeDriver();

driver.get(“http://www.google.com/&#8221);

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

System.out.println(driver.getTitle());

Thread.sleep(5000);

driver.findElement(By.cssSelector(“body”)).sendKeys(Keys.CONTROL + ”t”);

ChromeOptions options = new ChromeOptions();

options.addArguments(“–disable - extensions”);

driver = new ChromeDriver(options); driver.manage().window().maximize();

driver.get(“http://www.yahoo.com/&#8221);

System.out.println(driver.getTitle());

}

}


0 views

Contact Us

 Address.212, 2nd Floor, Grand Mall, Jalandhar, Punjab 144001, India

Tel. +91-7710795555

      +91-7710793555

QUICK LINKS

© 2019 by NTF. Proudly created with 9to5Technologies  privacy policy