今天在学习selenium的时候,运行程序报如下错误:
java.lang.UnsupportedClassVersionError:org/openqa/selenium/WebDriver : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(NativeMethod)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredMethods0(NativeMethod)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
at java.lang.Class.privateGetPublicMethods(Class.java:2743)
at java.lang.Class.getMethods(Class.java:1480)
at org.testng.internal.TestNGClassFinder.
at org.testng.TestRunner.initMethods(TestRunner.java:402)
at org.testng.TestRunner.init(TestRunner.java:228)
at org.testng.TestRunner.init(TestRunner.java:198)
at org.testng.TestRunner.
at org.testng.remote.support.RemoteTestNG6_0$1.newTestRunner(RemoteTestNG6_0.java:26)
atorg.testng.remote.support.RemoteTestNG6_0$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_0.java:59)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:561)
at org.testng.SuiteRunner.init(SuiteRunner.java:156)
at org.testng.SuiteRunner.
at org.testng.TestNG.createSuiteRunner(TestNG.java:1235)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1222)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1074)
at org.testng.TestNG.run(TestNG.java:999)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Java运行环境设置一致,都是JDK1.7,selenium包版本是3.7。
百度发现selenium-Java3.7的运行环境必须是jdk1.8。
测试了以下两种方法都可以解决:
一、首先将jdk1.7升级到jdk1.8
然后修改Windows-Preferences-Java-Compiler(设置为1.8)
Windows-Preferences-Java-Installed JREs(添加jdk1.8的安装路径)
项目-右键-Build Path-Configure Build Path-Libraries(将jdk1.7jar包换成1.8)
项目-右键-Properties-Java Compiler(设置为1.8)
二、将selenium-Java3.7的包换成selenium-Java2.4(jdk1.7环境)
在项目中选择pom.xml文件,如图所示,
将version下的LATEST修改为3.0以下版本
(注:注意selenium与火狐浏览器版本的对应关系。)