1

I'm using selenium to do web scraping and I'm trying to use a link to open a tab, whilst staying on the original tab. I have the following:

first_link.send_keys(Keys.CONTROL + Keys.RETURN)

which is meant to open the tab and navigate to it, but it just opens up the link in the original tab. Is there any way to open the link in a new tab, and furthermore, not navigate to it?

Thanks!

chris
  • 1,419
  • 3
  • 22
  • 41
  • http://stackoverflow.com/q/16180428/954442, http://stackoverflow.com/q/30406431/954442, http://stackoverflow.com/q/27628386/954442 – Andrew Regan Feb 27 '16 at 23:43
  • 1
    @AndrewRegan Those deal with either opening a new tab or switching between opened tabs. Doesn't answer his question to actively 'open a link in a new tab and in background'. – aneroid Feb 27 '16 at 23:49
  • I disagree, but OP's can decide what best works for him. – Andrew Regan Feb 27 '16 at 23:56

1 Answers1

0

You can't avoid switching to the new tab. You may want to set browser.tabs.loadInBackground to true (although that is the default).

Use Keys.CONTROL + Keys.ENTER (and not Keys.CONTROL + Keys.RETURN).
On Mac, it should be Keys.COMMAND + Keys.ENTER.

After that, to deal with switching between tabs and windows, check out these SO questions:

Community
  • 1
  • 1
aneroid
  • 11,031
  • 3
  • 33
  • 54