V
V
Vincent2019-05-14 22:11:06
Python
Vincent, 2019-05-14 22:11:06

Is it possible to open a new tab/window in Selenium?

Hello, I am working on the parser of one site, and at the behest of its creators, my parser needs to transfer information from one page to another with minimal loss of time, which is why the get () option is not suitable because it moves on a new one in the same tab link. My goal until the parser has started working is to open two tabs / windows at once, and switch between them when working.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2019-05-14
@wintreist

The easiest option is to create a new browser instance.
Another option is to run

driver.execute_script("window.open('https://google.com')")

About switching between windows: https://www.toolsqa.com/selenium-webdriver/switch-...
Now I came across another option using send_keys(Keys.CONTROL + 't')
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://stackoverflow.com/")

body = driver.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't')

driver.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question