简体   繁体   中英

python selenium, open link in new tab without navigating to it

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!

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM