Selenium WebDriver java.lang.UnsupportedClassVersionError:org/openqa/selenium/WebDriver:不支持major.minor 版本52.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43426076/
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
Selenium WebDriver java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 52.0
提问by user
I have
我有
- Eclipse eclipse-jee-luna-SR2-win32-x86_64
- Java - JRE7
- jdk-8u121-windows-x64
- Selenium Java Client Libraries - 3.3.1
- Eclipse eclipse-jee-luna-SR2-win32-x86_64
- Java - JRE7
- jdk-8u121-windows-x64
- Selenium Java 客户端库 - 3.3.1
I am trying to get started with Started with Selenium, I wrote a simple program but I am getting error msg:
我正在尝试开始使用 Started with Selenium,我编写了一个简单的程序,但收到错误消息:
"Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 52.0"
“线程“main”中的异常java.lang.UnsupportedClassVersionError:org/openqa/selenium/WebDriver:不支持major.minor版本52.0”
Below is the code:
下面是代码:
package com.automate;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test {
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "C:\Users\swati\Desktop\Selenium\chromedriver_win32_2.29\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}
}
回答by Thorbj?rn Ravn Andersen
The code has been compiled with and for Java 8
代码已使用 Java 8 编译并用于 Java 8
You need to run with Java 8 too.
您也需要使用 Java 8 运行。
回答by kushal.8
This error is probably because you are using Selenium 3.3.1
with Java 1.7
you need to upgrade java version to Java 1.8
OR
it could mean that your java compiler setting doesn't match with your project settings, In that case you have to goto :
此错误可能是因为您正在使用Selenium 3.3.1
withJava 1.7
您需要将 java 版本升级到Java 1.8
OR 这可能意味着您的 java 编译器设置与您的项目设置不匹配,在这种情况下,您必须转到:
Project > Properties > Java Compiler > and select java version to the one you're using in your project as follow:
项目 > 属性 > Java 编译器 > 并选择您在项目中使用的 Java 版本,如下所示:
回答by Rakib
The exception is generated from java.lang package, please take care of these observations. Because the java.lang.UnsupportedClassVersionError tells you this has nothing to do with selenium. That is probably why your question looks like duplicate and in risk of getting removed. You can check for a solution in the given possible duplicate link.
异常是从 java.lang 包产生的,请注意这些观察。因为 java.lang.UnsupportedClassVersionError 告诉你这与 selenium 无关。这可能就是为什么您的问题看起来重复并且有被删除的风险。您可以在给定的可能重复链接中检查解决方案。
According to your given data, you have jdk8 and jre7 versions. You need to be having either jdk7-jre7 or jdk8-jre8 pair. If your code was compiled in a higher version jdk (8) and the .class files are being run in lower jre (7), this is to be expected.
根据你给出的数据,你有 jdk8 和 jre7 版本。您需要拥有 jdk7-jre7 或 jdk8-jre8 对。如果您的代码是在更高版本的 jdk (8) 中编译的,并且 .class 文件在更低版本的 jre (7) 中运行,那么这是意料之中的。
So check your project settings from kushal's answer. or compile directly with a compatible/desirable jre version (from https://stackoverflow.com/a/11432195/2453382)
因此,请从 kushal 的回答中检查您的项目设置。或直接使用兼容/理想的 jre 版本编译(来自https://stackoverflow.com/a/11432195/2453382)
javac -target 1.7 Test.java
javac -target 1.7 Test.java