0

I am writing the selenium UI tests. I need to open the link in new tab after I click the URL. I used the below code but didn't work.

Actions action = new Actions(WebDriver);
action.KeyDown(Keys.Control).MoveToElement(TermsOfUseLinkElement).KeyUp(Keys.Control).Click().Build().Perform();

Any other suggestions?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • See this [SO thread](https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver). It's java and not C#, but the selenium wrapper is almost the same in most languages, so you should be able to make working solution. – SoptikHa Sep 25 '18 at 21:07

2 Answers2

0

I have found the answer.

 ((IJavaScriptExecutor)WebDriver).ExecuteScript("window.open('" + TermsOfUseLinkElement + "','_blank');"); 
0

If you still want to stick with Actions you can use the following solution:

Actions action = new Actions(WebDriver);
action.keyDown(Keys.Control).Click(TermsOfUseLinkElement).KeyUp(Keys.Control).Build().Perform();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried this one. But If i am hitting the multiple links, this was not working. –  Sep 26 '18 at 20:33
  • @AshokYaganti In the question heading/description you mentioned about `open the link in new tab`, your code trials is for a single link, from where does **hitting the multiple links** comes from? Can you shed some light? – undetected Selenium Sep 26 '18 at 20:51