1
votes

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.

3
Have you specified a particular version of Java in your pom.XML? - robjwilkins
Basically a 1.6 JRE is trying to run 1.7 classes, though you don't say how you're trying to run your application. You basically need to check the version of each JRE you're invoking and ensure it's >= 1.7. Start with your Java Build Path. - Andrew Regan
Do you have a 'JRE System Library' or equiv in your project view? What version does it say? Should be same as what Preferences > Java Build Path says, which needs to be 1.7+ (1.8 even better) - Andrew Regan
So this is where the Java 6 comes in. It's fine to have multiple versions, but you can't mix old ones with new classes. Change that to 7+ (ideally 8), clean and rebuild everything, and you should be OK. - Andrew Regan
Good news! I've summed-up the discussion in an answer so future generations can see what worked. - Andrew Regan

3 Answers

1
votes

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.

0
votes

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.

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

0
votes

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