how to open a link in new tab (chrome) using selenium webdriver?

0
0
System.setProperty("webdriver.chrome.driver", "D:\\softwares\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver
.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver
.manage().window().maximize();
driver
.get("https://mail.google.com/");
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver
.findElement(By.linkText("www.facebook.com")).sendKeys(selectLinkOpeninNewTab);

new tab is opening but url link is not opening

  • You must to post comments
0
0

I checked with below code and it works fine for me. I found answer from here.

    driver = new ChromeDriver();
driver
.manage().window().maximize();
baseUrl
= "http://www.google.co.uk/";
driver
.get(baseUrl);
driver
.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver
.switchTo().window(tabs.get(1)); //switches to new tab
driver
.get("https://www.facebook.com");
driver
.switchTo().window(tabs.get(0)); // switch back to main screen
driver
.get("https://www.news.google.com");
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website