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

爷,独闯天下 提交于 2020-01-25 01:27:30

问题


After upgrading to firefox 68 my selenium python script broke, I wasn't able to open a new tab using the code that worked prior.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

my_profile = webdriver.FirefoxProfile()

my_profile.set_preference("browser.tabs.remote.autostart", False)
my_profile.set_preference("browser.tabs.remote.autostart.1", False)
my_profile.set_preference("browser.tabs.remote.autostart.2", False)
browser = webdriver.Firefox(firefox_profile=my_profile)

browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')

回答1:


Turns out Mozilla made changes to future Firefox versions starting firefox 68,

so changing "browser.tabs.remote.autostart” value to false, simply won’t disable e10s (Multi-Process)

and as a result won't open a new tab in selenium.

you can read more about it here:

https://techdows.com/2019/05/mozilla-firefox-68-doesnt-allow-turning-off-e10s.html

https://www.ghacks.net/2016/07/22/multi-process-firefox/


The solution is to delete the previous code and use this instead:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os

os.environ['MOZ_FORCE_DISABLE_E10S'] = '1'
browser = webdriver.Firefox()

browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')


来源:https://stackoverflow.com/questions/56973213/how-to-fix-selenium-webdriver-not-opening-a-new-tab-on-firefox-68-0-and-above

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!