简体   繁体   中英

Python: Selenium New Tab

I am using Firefox v67.0.4 with geckodriver 0.24.0 and I tried several methods to open a new tab, but the only thing Firefox is doing, is opening a new window .

Are there any other approaches to open new tabs next to these two:

1.)

driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[tab_index])
driver.get(link)

2.)

driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
driver.switch_to.window(driver.window_handles[tab_index])
driver.get(link)

Am I doing something wrong or is it a bug with the current versions?

I had the same problem. this is the code I use to open a new tab and switch to it:

driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
windows = browser.window_handles
time.sleep(1)
driver.switch_to.window(windows[tab_index])

but starting from Firefox 68.0 you also need to add the code shown here:

How to fix Selenium Webdriver not opening a new tab on Firefox 68.0 and above?

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