硒NoSuchMethodError [英] Selenium NoSuchMethodError
问题描述
我正在编写一个自动化测试框架,并且已经编写了大量.但是,我遇到了一个错误,似乎无法修复或找到解决方案.
I am writing an automated test framework and have already written a substantial amount. However, I have come across an error which I cannot seem to fix or find a solution for.
当硒尝试回答日期问题并从日期的下拉菜单中选择时,就会出现问题.我已经完成了很多工作,没有任何问题,但是由于某种原因,我得到了标题中显示的错误.尝试在Google上找到解决方案后,我决定来到这里,因为那里似乎没有类似的东西.
The problem occurs when selenium tries to answer a date question and select from a dropdown menu of dates. I have achieved this loads of times with no problems, but for some reason I get the error as displayed in the title. After trying to find a solution on google I decided to come here as there seems to be nothing out there that's similar.
我的自动测试中断的代码是:
The code where my automated test breaks is:
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
和selectByIndex
的行上发生错误.在使用Selenium IDE的浏览器中运行测试时,我已经使用这些方法数百次了.但是,一旦将代码转移到Eclipse,它就无法正常工作.
The error occurs on the lines where the methods selectByVisibleText
and selectByIndex
is used. I have used these methods hundreds of times before with no issues.. When I run the tests in the browser with the Selenium IDE it executes with no problems. But as soon as the code is transferred across to Eclipse it doesnt work.
我唯一能想到的就是我已经将项目从JUnit转换为TestNG.这会有什么影响吗?尽管没有任何问题,我之前已经做到了.
The only thing I can possibly think of is that I have converted the project from JUnit to TestNG.. Would this have any implications? I have done this before though without any issues.
任何帮助将不胜感激!
Stacktrace:
Stacktrace:
java.lang.NoSuchMethodError:org.openqa.selenium.WebElement.setSelected()V
java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected()V
在org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:111)
at org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:111)
在tns_automation.DHP_Forms.DhpAbstractTest.answerAmountOfDHPQuestion(DhpAbstractTest.java:348)
at tns_automation.DHP_Forms.DhpAbstractTest.answerAmountOfDHPQuestion(DhpAbstractTest.java:348)
tns_automation.DHP.KnowsleyDHPTest.completeAssessmentFormAndBudgetTool,然后下载PDFFromInTrayWithCookiesEnabled(KnowsleyDHPTest.java:62)
at tns_automation.DHP.KnowsleyDHPTest.completeAssessmentFormAndBudgetToolBeforeDownloadingPDFFromInTrayWithCookiesEnabled(KnowsleyDHPTest.java:62)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:498)
at java.lang.reflect.Method.invoke(Method.java:498)
在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
在org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
在org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
在org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
在org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
在org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
在org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.TestRunner.run(TestRunner.java:602)
在org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
在org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
在org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
在org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
在org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
在org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.runSuites(TestNG.java:1144)
在org.testng.TestNG.run(TestNG.java:1115)
at org.testng.TestNG.run(TestNG.java:1115)
在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
推荐答案
已通过将最新的硒Maven依赖项导入到我的pom.xml中解决了此问题.我在其他项目中使用它时,仍然不明白为什么会发生此问题. Maven依赖项可以解决此问题:
This issue has been resolved by importing the latest selenium maven dependency in to my pom.xml. I still can't understand why this issue occurred as I have used it in other projects. The maven dependency to fix the issue:
<!-- 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>
这篇关于硒NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!