1

When searching for how to open a new tab using Selenium WebDriver, I found this question:

How to open a new tab using Selenium WebDriver with Java?

However, the question specifically mentions firefox, and additionally the advice to use sendKeys with ctrl + t is windows-specific (on a mac, it's command + t, and I also don't know if other browsers follow the same keyboard-shortcut conventions).

If I can, I'd like to avoid trying to detect what browser and what platform I'm using to determine what keys I should send to open a new tab. Is there a clean, simple, and platform/browser agnostic way to open a new tab using Selenium WebDriver?

Community
  • 1
  • 1
James Dunn
  • 8,064
  • 13
  • 53
  • 87

1 Answers1

1

You can execute javascript "window.open('http://stackoverflow.com/')"

But the default profile SE uses, may be blocking popups. In that case, you would need to address this when instantiating the browser.

For Chrome, add this argument to your chromeOptions:

options.addArguments("disable-popup-blocking");
Dingredient
  • 2,191
  • 22
  • 47
  • 1
    Thanks, Pat. I'm ok with dealing with disabling popups as you suggested, since I can do that in another part of my testing infrastructure and don't have to think about it in my "new tab" method. This actually opens a new window, not just a new tab, but for my purposes it's the same thing. So this works for me. Thanks! – James Dunn Aug 20 '14 at 22:34