如何将Selenium连接到现有的Firefox浏览器?(Python)

3

有人知道如何将现有的Firefox浏览器与Selenium连接吗?我尝试了Chrome的方法,但没有成功。

以调试模式启动Firefox:

start firefox.exe --marionette -foreground -no-remote -profile C:\FirefoxTEMP

我写的 Python 代码:
from selenium import webdriver
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9224")
drivePath = r'C:\\geckodriver.exe'
driver = webdriver.Firefox(options= options, executable_path = drivePath)

我猜这是启动调试模式的问题。在Chrome中,我可以通过一个命令和一个端口来做到这一点:

chrome.exe --remote-debugging-port=9223 --user-data-dir="C:\selenum\ChromeProfile"

selenium==4.8.0中,selenium.webdriver.firefox.options.Options没有add_experimental_option()方法。 - akaihola
1个回答

1
更新。以更好的方式打开Firefox调试模式(默认端口为6000):
firefox.exe --start-debugger-server --profile C:\FirefoxTEMP

3
但是 add_experimental_option() 方法在 Firefox 中不可用... - Jerry T

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接