如何修复Selenium Webdriver无法在Firefox 68.0及更高版本上打开新标签页?
升级到firefox 68之后,我的硒python脚本坏了, 我无法使用之前可用的代码打开新标签.
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')
结果表明Mozilla对从firefox 68开始的未来Firefox版本进行了更改,
Turns out Mozilla made changes to future Firefox versions starting firefox 68,
因此将"browser.tabs.remote.autostart"值更改为false, 根本不会禁用e10s(多进程)
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')