eclipse Selenium webdriver Unsupported major.minor version 51.0 - Java 版本问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36295023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:06:26  来源:igfitidea点击:

Selenium webdriver Unsupported major.minor version 51.0 - Java version issue

javaeclipsemavenselenium-webdriver

提问by user3861559

I am setting selenium web driver. I set it up as Maven project.

我正在设置硒网络驱动程序。我将它设置为 Maven 项目。

My basic "Hello world" equivalent tests that are not using webdriver is class is working fine. How ever when I tried using the code breaks and I get the following error.

我不使用 webdriver 的基本“Hello world”等效测试是类工作正常。当我尝试使用代码中断时,我如何收到以下错误。

WebDriver driver = new FirefoxDriver();

java.lang.UnsupportedClassVersionError: org/openqa/selenium/firefox/FirefoxDriver : Unsupported major.minor version 51.0

java.lang.UnsupportedClassVersionError: org/openqa/selenium/firefox/FirefoxDriver: 不支持major.minor 版本51.0

From what I understand it is a java version issue. So, I went ahead and installed Java 1.8.

据我了解,这是一个java版本问题。所以,我继续安装了 Java 1.8。

When I run java -versionI get this:

当我跑步时,java -version我得到了这个:

java version "1.8.0_77" Java(TM) SE Runtime Environment (build 1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

java 版本“1.8.0_77”Java(TM) SE 运行时环境(构建 1.8.0_77-b03)Java HotSpot(TM) 64 位服务器 VM(构建 25.77-b03,混合模式)

But still my code breaks.

但我的代码仍然中断。

  1. My bash profile still reads java 1.6 export PATH="/Users/pathToPerForce/p4/JavaLib/main/build/apache-ant-1.6.3/bin:/Applications/p4:${PATH}

  2. When I set up this as Maven project I could right click on project and "build as" maven build. Now that is failing too.

  1. 我的 bash 配置文件仍然读取 java 1.6 export PATH="/Users/pathToPerForce/p4/JavaLib/main/build/apache-ant-1.6.3/bin:/Applications/p4:${PATH}

  2. 当我将它设置为 Maven 项目时,我可以右键单击项目并“构建为”maven 构建。现在这也失败了。

I am fairly new to java and selenium and not able to comprehend this is good depth. Any help in fixing this is much appreciated.

我对 java 和 selenium 相当陌生,无法理解这是很好的深度。非常感谢解决此问题的任何帮助。

采纳答案by Andrew Regan

Just to sum up the comments: the analysis was that a 1.6 JRE was trying to run 1.7 (version 51) classes.

总结一下评论:分析是 1.6 JRE 试图运行 1.7(版本 51)类。

It's fine to combine multiple JRE/JDK versions provided that older versions don't try to run classes created by a newer (major) version.

如果旧版本不尝试运行由较新(主要)版本创建的类,则可以组合多个 JRE/JDK 版本。

The solution was simply to change the Eclipse project's Java Build Path, replacing the Java SE 6 [1.6.0_65]entry that was there with a 1.7 or 1.8 version.

解决方案只是更改 Eclipse 项目的Java Build Path,用Java SE 6 [1.6.0_65]1.7 或 1.8 版本替换那里的条目。

回答by preetam kumar samal

I too was facing the same issue but with chrome driver. error: ...Unsupported major.minor version 51.0 All I did is, I installed 1.8 jre, Configures it in the BUILD PATH and the issue got resolved.

我也面临同样的问题,但使用 chrome 驱动程序。错误:...不支持的major.minor 版本51.0 我所做的只是,我安装了1.8 jre,在BUILD PATH 中配置它,问题得到解决。

RCA: The dependency jars I was using is configurable with latest version of jre.

RCA:我使用的依赖 jar 可以使用最新版本的 jre 进行配置。

回答by Swati Patel

If you have tried with all the options like updating the PATH variable, changing the eclipse properties in project - > properties -> java compiler - > JDK Compliance and then correct the JRE version here still facing the same issue then try to check the versions of reference jar. In my case I was trying to write code for selenium webdriver (Standalone server + client). I was getting the issue with version 3. on words. I have degraded the version to 2.5 and it worked fine. Also, check the version of java compiler and java with below command. Both should be same javac - version :- Compiler version java - version :- java version

如果您尝试了所有选项,例如更新 PATH 变量、更改项目中的 eclipse 属性 -> 属性 -> java 编译器 -> JDK 合规性,然后在此处更正 JRE 版本仍然面临同样的问题,然后尝试检查版本参考罐子。就我而言,我试图为 selenium webdriver(独立服务器 + 客户端)编写代码。我遇到了版本 3. 关于文字的问题。我已经将版本降级到 2.5 并且运行良好。另外,使用以下命令检查 java 编译器和 java 的版本。两者应该是相同的 javac - version :- 编译器版本 java - version :- java version