python - 如何修复 Selenium Webdriver 在 Firefox 68.0 及更高版本上无法打开新选项卡的问题?

标签 python selenium firefox environment-variables

升级到 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/

相关文章:

python - 为 pandas 中的所有列生成列矩阵

python - 如何使项目在 Python Spyder Project Explorer 中显示

python - 如何在 Xvfb 中运行 Selenium?

Python:元素不是可点击的 Selenium

javascript - Firefox 插件将计算列出的 url 的点击次数

python - k_clique_communities 的结果

Python Selenium - 如何处理直到 WebDriverWait 完成后才显示的警报?

apache - Firefox 的站点非常慢,在所有其他浏览器上都是即时的 : KeepAlive issue?

python - Selenium Python selenium.common.exceptions.WebDriverException : Message: connection refused using geckodriver and firefox

python - perl ssh 密码