python - 使用 Marionette 添加 Firefox 的第二个实例(更改端口)

标签 python firefox firefox-marionette

我在通过木偶创建两个 Firefox 实例时遇到了很大的困难。有一个实例工作正常:

在启用 marionette 的情况下启动 Firefox:

firefox.exe -marionette

用python控制它:

from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.execute_script("alert('o hai there!');")

现在我想在当前客户端旁边添加第二个客户端,quick search导致 --address 命令:

firefox.exe -marionette --address=localhost:2829

试图通过 python 控制它:

from marionette import Marionette
client = Marionette('localhost', port=2829)
client.start_session()
client.execute_script("alert('o hai there!');")

我似乎无法让它工作,但是:

error: [Errno 10061] No connection could be made because the target machine actively refused it

非常感谢任何帮助。

最佳答案

你必须使用不同的配置文件让 firefox 监听不同的端口。
编辑 <path-to-profile>/prefs.js添加以下内容并保存当 firefox 未使用此配置文件时

user_pref("marionette.defaultPrefs.port", 2829);

现在,启动 firefox;

firefox -marionette --profile <path-to-profile> --new-instance&

创建一个新的配置文件;

$ mkdir new_profile
$ firefox --profile new_profile --new-instance

然后关闭火狐。现在你将拥有 new_profile/prefs.js

关于python - 使用 Marionette 添加 Firefox 的第二个实例(更改端口),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514778/

相关文章:

css - 样式表无法在 ie11 或 firefox 上加载

css - 更改 HTML5 音频标签中的控件颜色

java - Selenium Webdriver 中 MarionetteDriver 的 FirefoxDriver(*profile*) 等效吗?

python - 如何在 Mozilla - Marionette 网络驱动程序中设置特定的下载位置?

python - 使用 AUTH=NTLM 针对 Exchange imap 服务器验证 imaplib.IMAP4_SSL

python - 使用 selenium (Python) 轮换服务器 IP

用于 minimax 的 Python n 叉树

selenium - 火狐木偶绕过安全异常

python - 在 Pandas 中减少(折叠)

javascript - 多语言库的 python 位的文件布局和 setuptools 配置