java - Selenium 4 : Getting java. lang.NoSuchMethodError : org. openqa.selenium.WebElement.getDomAttribute(Ljava/lang/String;)Ljava/lang/String;

标签 java selenium selenium-webdriver nosuchmethoderror selenium4

我在 chrome 97 中使用 selenium“4.1.2”。使用选择类从下拉列表中选择值时,出现异常:

java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.getDomAttribute(Ljava/lang/String;)Ljava/lang/String;

以下是我的项目中的依赖项:

                    ext {
                selenium = '4.1.2'
                webdrivermanager = '5.0.3'
            }
            dependencies {
                compile("org.seleniumhq.selenium:selenium-java:${selenium}")
            //    compile("io.github.bonigarcia:webdrivermanager:${webdrivermanager}")
                testImplementation "org.seleniumhq.selenium:selenium-chrome-driver:${selenium}"
                testImplementation "org.seleniumhq.selenium:selenium-firefox-driver:${selenium}"
                testImplementation "org.seleniumhq.selenium:selenium-ie-driver:${selenium}"
                testImplementation "org.seleniumhq.selenium:selenium-edge-driver:${selenium}"
                testImplementation "org.seleniumhq.selenium:selenium-safari-driver:${selenium}"
                testImplementation "org.seleniumhq.selenium:selenium-remote-driver:${selenium}"
                testImplementation "org.seleniumhq.selenium:selenium-support:${selenium}"
                testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
                testImplementation 'org.hamcrest:hamcrest:2.1'
                testImplementation 'org.hamcrest:hamcrest-library:2.1'
                testCompile("org.junit.jupiter:junit-jupiter-api:5.7.2")
                testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
                testRuntime("org.junit.platform:junit-platform-launcher:1.7.2")
                testCompile('io.github.bonigarcia:selenium-jupiter:3.3.4')
                compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.11.0'
                compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.16'
                implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
                implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
                compile group: 'io.qameta.allure', name: 'allure-gradle', version: '2.7.0'
                compile 'org.apache.maven.plugins:maven-surefire-plugin:2.21.0'
                compile('com.assertthat:selenium-shutterbug:1.5')
                compile 'org.slf4j:slf4j-nop:1.7.25'
                implementation group: 'javax.mail', name: 'mail', version: '1.4.7'
                implementation group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
                runtimeClasspath group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
                compile group: 'net.lightbody.bmp', name: 'browsermob-core', version: '2.1.4'
                compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
                compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.4'
                compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4'
                implementation group: 'org.json', name: 'json', version: '20201115'
                implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
                testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2'
                testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.7.2'
                testImplementation group: 'org.junit.platform', name: 'junit-platform-surefire-provider', version: '1.3.2'

            }

非常感谢您为解决此问题提供的任何帮助。

最佳答案

此错误消息...

java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.getDomAttribute(Ljava/lang/String;)Ljava/lang/String;

...是依赖版本冲突的结果。


深入探讨

根据@titusfortner commentdiscussion您需要交叉检查与 Selenium 相关的所有内容是否都设置为 4.x 并且没有任何需要 Selenium 的内容 3.x(例如 Appium 7)作为 comment 中的 @asolntsev 包含在您的依赖项中提及:

All implementations of WebElement do override method getDomAttribute(). It never throws UnsupportedOperationException in real life.


解决方案

您需要执行mvn dependency:treegradle dependency,您将能够跟踪问题如本example中所述.

关于java - Selenium 4 : Getting java. lang.NoSuchMethodError : org. openqa.selenium.WebElement.getDomAttribute(Ljava/lang/String;)Ljava/lang/String;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70991486/

相关文章:

c# - 等待页面加载

python - 在 Python 中使用 Selenium 处理 "Accept Cookies"弹出窗口

java - 添加带有过期时间的 cookie 时,Cookie 过期时间必须为正整数 最大 java 日期 Aug 17, 292278994 12 :42:55 PM

java - 在同一范围内调用两次具有数组输出的方法

java - 在 Selenium 中绕过验证码

java - 在 Java 中表示浮点值

ajax - 使用 Selenium for Firefox 选择 Ajax 下拉建议列表

selenium - WebDriver、ChromeDriver 和 Browser 之间如何通信?什么是 WIRE 协议(protocol)?

java - ExecutorService、newFixedThreadPool 和 setPrioirty

java - 在 mbedtls Diffie-Hellman 中使用来自 Java 的 DER key