gpt4 book ai didi

java - 在 Selenium Webdriver 中将 DesiredCapability 与 FirefoxOptions 合并会导致 java.lang.NoSuchMethodError

转载 作者:行者123 更新时间:2023-12-01 18:34:22 24 4
gpt4 key购买 nike

当我尝试启动 Selenium WebDriver 时,我收到:NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge:

我在 main 中的代码调用单个方法:

WebDriver driver = new WebDriverProfile().getTMPFirefoxProfile(null); // Parameter is optional

我详细发布了我的代码,希望有人能够提供建议来指导我走向正确的方向。

堆栈跟踪:

Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge(Lorg/openqa/selenium/Capabilities;)Lorg/openqa/selenium/firefox/FirefoxOptions;
at webdriverX.WebDriverProfile.getTMPFirefoxProfile(WebDriverProfile.java:286)
at n.NMain.main(NMain.java:22)

getTMPFirefoxProfile(ProxyPOJO proxyPOJO) 的调用调用代码:

public WebDriver getTMPFirefoxProfile(ProxyPOJO proxyPOJO) throws InterruptedException, MalformedObjectNameException, InstanceNotFoundException, ReflectionException {

System.setProperty("webdriver.gecko.driver", GlobalVar.geckdriverExecutableFilePath); // Verified path is correct via syso


DesiredCapabilities capabilities = new DesiredCapabilities();

if (proxyPOJO != null) {

Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
proxy.setFtpProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
proxy.setSslProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());


capabilities.setCapability(CapabilityType.PROXY, proxy);
}


DesiredCapabilities dc = DesiredCapabilities.firefox();


FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);


opt.addPreference("dom.popup_maximum", 200);
opt.addPreference("dom.webnotifications.enabled", false);


opt.merge(capabilities);

WebDriver driver = WebDriverX.getNewFireFoxWebDriver(opt);



return driver;
}

调用:getNewFireFoxWebDriver(FirefoxOptions firefoxOptions) 调用此代码:

if (firefoxOptions != null) {
driver = new FirefoxDriver(firefoxOptions);
} else {
driver = new FirefoxDriver();
}

return driver;

我问过a similar question然而我现在已经尝试了近 10 种不同的建议 - 没有一个能解决我的问题。

下面我将概述我为解决该问题而采取的步骤:

1) 右键单击​​项目 -> Maven clean -> Maven build -> Maven test(我分别尝试了每一个,然后在下一个之后全部尝试)

2) 单击项目 -> 清理

3) 确认 Firefox 已更新至最新版本(版本 72)

4) 从项目 POM 中删除了库 guava(唯一建议的冲突)

5) 关闭并重新启动 Eclipse

6)删除了所有运行配置并从头开始运行项目

7) 重新下载 GeckoDriver v0.26.0 以确保我安装了最低版本

8) 我确保我的 POM 文件包含 Selenium 依赖项版本 3.141.591,其中包含 合并方法

我别无选择。接下来我该尝试什么?

以下是项目 POM 文件的内容:

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
</dependency>

<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
<classifier>models</classifier>
</dependency>

<dependency>
<groupId>uk.ac.abdn</groupId>
<artifactId>SimpleNLG</artifactId>
<version>4.4.8</version>
</dependency>

</dependencies>

我在该项目的构建路径中链接了另外两个项目。从一个项目中,我可以毫无问题地调用 getTMPFirefoxProfile(ProxyPOJO proxyPOJO)。从另一个项目中,我得到了与当前项目相同的错误。这是什么意思?我分析了其他项目,没有发现任何冲突的依赖关系。

我花了一整天的时间试图解决这个问题,但我感觉完全迷失了..

有什么想法吗?

谢谢!

最佳答案

在您的 previous question 中涵盖了所有可能的问题以及此问题的解决方案之后看来你现在已经很接近了。

此外,我建议安装 Selenium使用 的 Java 库您应该添加 <selenium-java>项目中的依赖项 pom.xml首先,因为它将支持使用所有 Selenium 支持的浏览器运行您的自动化项目。:

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

更进一步,如果您只想在 Firefox 中运行测试,则可以替换为 selenium-firefox-driver依赖:

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.141.59</version>
</dependency>

关于java - 在 Selenium Webdriver 中将 DesiredCapability 与 FirefoxOptions 合并会导致 java.lang.NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60088229/

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