硒NoSuchMethodError

2024-03-15

我正在编写一个自动化测试框架,并且已经写了很多。但是,我遇到了一个似乎无法修复或找到解决方案的错误。

当 selenium 尝试回答日期问题并从日期下拉菜单中进行选择时,就会出现问题。我已经完成了很多次,没有任何问题,但由于某种原因,我收到了标题中显示的错误。在尝试在谷歌上找到解决方案后,我决定来这里,因为那里似乎没有类似的解决方案。

我的自动化测试中断的代码是:

new Select(driver.findElement(By.id("AMOUNT_OF_DHP_DATE_FROM_d"))).selectByVisibleText("4th");

new Select(driver.findElement(By.id("AMOUNT_OF_DHP_DATE_FROM_m"))).selectByIndex(4);
    driver.findElement(By.id("AMOUNT_OF_DHP_DATE_FROM_y")).sendKeys("2017");
    driver.findElement(By.id("AMOUNT_OF_DHP_WEEKLY")).sendKeys("50");

new  Select(driver.findElement(By.id("AMOUNT_OF_DHP_DATE_TO_d"))).getFirstSelectedOption();

new Select(driver.findElement(By.id("AMOUNT_OF_DHP_DATE_TO_m"))).getFirstSelectedOption();

driver.findElement(By.id("AMOUNT_OF_DHP_DATE_TO_y")).sendKeys("2017");
clickNext();

错误发生在方法所在的行上selectByVisibleText and selectByIndex用来。我之前已经使用这些方法数百次,没有任何问题。当我使用 Selenium IDE 在浏览器中运行测试时,它执行时没有任何问题。但是一旦代码转移到 Eclipse 中,它就不起作用了。

我唯一能想到的就是我已将项目从 JUnit 转换为 TestNG。这会产生任何影响吗?我以前曾这样做过,但没有任何问题。

任何帮助将不胜感激!

EDIT

堆栈跟踪:

java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected()V

在 org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:111)

在 tns_automation.DHP_Forms.DhpAbstractTest.answerAmountOfDHPQuestion(DhpAbstractTest.java:348)

在 tns_automation.DHP.KnowsleyDHPTest.completeAssessmentFormAndBudgetToolBeforeDownloadingPDFFromInTrayWithCookiesEnabled(KnowsleyDHPTest.java:62)

在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)

在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

在 java.lang.reflect.Method.invoke(Method.java:498)

在 org.testng.internal.MethodInitationHelper.invokeMethod(MethodInitationHelper.java:108)

在 org.testng.internal.Invoker.invokeMethod(Invoker.java:661)

在 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)

在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)

在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)

在 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)

在 org.testng.TestRunner.privateRun(TestRunner.java:744)

在 org.testng.TestRunner.run(TestRunner.java:602)

在 org.testng.SuiteRunner.runTest(SuiteRunner.java:380)

在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)

在 org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)

在 org.testng.SuiteRunner.run(SuiteRunner.java:289)

在 org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

在 org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)

在 org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)

在 org.testng.TestNG.runSuitesLocally(TestNG.java:1226)

在 org.testng.TestNG.runSuites(TestNG.java:1144)

在 org.testng.TestNG.run(TestNG.java:1115)

在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)

在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)

在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)


通过将最新的 selenium maven 依赖项导入到我的 pom.xml 中,此问题已得到解决。我仍然不明白为什么会出现这个问题,因为我在其他项目中使用过它。解决该问题的 Maven 依赖项:

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.3.1</version>
    </dependency>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

硒NoSuchMethodError 的相关文章

随机推荐