0

I am trying to write a short scrip, which will help me open links from the list in separate browser tabs using Selenium/Python.

Here is the sample of my code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get(https://www.google.com/)
links = ['link_1', 'link_2', 'link_3']
for link in links:
    # open a new tab
    driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
    driver.get(link)

I using Opera 67. Somehow, the combination of keys Control + t doesn't work, pages are being opened one after another in the same tab. Any hint will be appreciated!

1 Answer 1

1

Another way to open new tab, you can use .execute_script like below:

driver.get("https://www.google.com/")
links = ['link_1', 'link_2', 'link_3']
for link in links:
    # open a new tab
    driver.execute_script("window.open('" +link +"');")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.