如何修复Selenium Webdriver无法在Firefox 68.0及更高版本上打开新标签页? [英] How to fix Selenium Webdriver not opening a new tab on Firefox 68.0 and above?

查看:309
本文介绍了如何修复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')

这篇关于如何修复Selenium Webdriver无法在Firefox 68.0及更高版本上打开新标签页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆