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

eclipsejavamavenselenium-webdriver

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

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 driver = new FirefoxDriver();

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

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

When I run java -version I get this:

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)

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.

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.

Best Answer

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

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.

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.

Related Topic