升级到 Firefox 68 后,我的 selenium python 脚本坏了, 我无法使用之前有效的代码打开新选项卡。
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')
最佳答案
事实证明,从 Firefox 68 开始,Mozilla 对 future 的 Firefox 版本进行了更改,
因此将“browser.tabs.remote.autostart”值更改为 false, 根本不会禁用 e10s(多进程)
因此不会在 selenium 中打开新选项卡。
您可以在这里阅读更多相关信息:
https://techdows.com/2019/05/mozilla-firefox-68-doesnt-allow-turning-off-e10s.html
https://www.ghacks.net/2016/07/22/multi-process-firefox/
<小时/>解决方案是删除之前的代码并使用此代码:
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')
关于python - 如何修复 Selenium Webdriver 在 Firefox 68.0 及更高版本上无法打开新选项卡的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56973213/