gpt4 book ai didi

java - 运行另一个 firefox.exe,而不是默认使用 Remote WebDriver 实现的 firefox.exe

转载 作者:行者123 更新时间:2023-12-01 09:37:40 25 4
gpt4 key购买 nike

我正在使用 selenium,并且我会将 selenium 与特定文件夹中的 firefox.exe 一起使用,而不是已安装的文件夹。为此,我有以下代码:

System.setProperty("webdriver.firefox.bin", "./firefox-sdk/bin/firefox.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();

cap.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL(node), cap);

代码可以工作,但问题是当我使用 setProperty 时,它继续在 Program Files 文件夹中运行 Firefox,而不是在指定文件夹中运行,我做错了什么?

最佳答案

有两种方法可以启动未安装在程序文件中的 Firefox 版本。

方法1:使用FirefoxBinary

File pathToBinary = new File("./firefox-sdk/bin/firefox.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("firefox_binary", pathToBinary);
driver = new RemoteWebDriver(new URL(node), cap);

方法2:使用webdriver.firefox.bin属性

在这种情况下,您必须在上述路径中安装另一个版本的 Firefox,然后您可以使用 System.setProperty() 设置属性 webdriver.firefox.bin

关于java - 运行另一个 firefox.exe,而不是默认使用 Remote WebDriver 实现的 firefox.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38723366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com