【问题标题】:How to install add-on on a remote Firefox webdriver?如何在远程 Firefox 网络驱动程序上安装附加组件?
【发布时间】:2018-07-23 05:43:28
【问题描述】:
install_addon 是 Firefox 网络驱动程序上的一种方法,但我正在远程运行测试。如何将附加组件安装到驱动程序,如下所示:
driver = webdriver.Remote(
command_executor=SELENIUM_URL,
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX
)
?看起来创建一个webdriver.FirefoxProfile() 并使用add_extension() 应该可以工作,但是it's currently broken。
use case 正在测试 Firefox 插件 manifest.json 的 all_frames 属性的效果。
【问题讨论】:
标签:
python
selenium
firefox
【解决方案1】:
-在谷歌对这个主题进行长时间搜索和访问后,我找到了解决方案
从浏览器在您的 Firefox 配置文件中安装插件,保存并将其设置为 webdriver 选项。
Firefox 配置文件创建
- 打开你
firefox浏览器
- 转到
about:profiles
- 创建新配置文件
- 使用创建的配置文件启动浏览器
- 安装所需的插件
导出配置文件
- 打开 Firefox 配置文件的根目录(参见
about:profile 中的 Root Directory 部分)
- 将文件夹复制到您的项目中
Python
from selenium.webdriver import FirefoxOptions, FirefoxProfile, Remote
# init options object
options = FirefoxOptions()
# init profile object with path to you profile
profile = FirefoxProfile('{path_to_your_profile_folder}')
# set profile into options
options.profile = profile
# init you Remote browser with created options (commented arguments for example)
driver = Remote(
options=options,
# command_executor= ...,
# desired_capabilities=...
)
它对我有用。此解决方案的缺点是存在需要将配置文件存储在某处的文件夹