java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 52.0 error with Selenium through Java 7

China☆狼群 提交于 2021-02-05 08:28:06

问题


This is the code of selenium code to open the chrome browser and closing it.

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;

public class TC001_Login_Logout 
{
    public static void main(String args[]) throws Exception
     {
        System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Selenium\\chrome");
        WebDriver driver = new ChromeDriver();

        driver.get("http://127.0.0.1/orangehrm-2.6/login.php"); 
        System.out.println("Application opened");

        driver.findElement(By.name("txtUserName")).sendKeys("admin");

        driver.findElement(By.name("txtPassword")).sendKeys("admin");
        driver.findElement(By.name("Submit")).click(); 

        Thread.sleep(3000);
        System.out.println("Login completed");

        driver.findElement(By.linkText("Logout")).click();
        System.out.println("Logout completed");

        driver.close(); //close browser
    }
}

After running the above program I am getting run time exception. I have java jdk version7 installed in my system. How can i get rid of this error. Need help from you guys. This is my first selenium program.

Error message:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : 
Unsupported major.minor version 52.0 (lines)---> 1.at java.lang.ClassLoader.defineClass1(Native Method) 2.atjava.lang.ClassLoader.defineClass(UnknownSource)atjava.security.SecureClassLoader.defineClass(Unknon Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source)at java.net.URLClassLoader$1.run(Unknown Source)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(Unknown Source)atjava.lang.ClassLoader.loadClass(UnknownSource)atsun.misc.Launcher$AppClassLoader.loadClass(Unkown Source) at java.lang.ClassLoader.loadClass(Unknown Source)atjava.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getMethod0(Unknown Source)at java.lang.Class.getMethod(Unknown Source)at sun.launcher.LauncherHelper.getMainMethod(Unknown Source).
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

回答1:


This error message...

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 52.0

...describes the version of the JRE with which the org/openqa/selenium/WebDriver class file is compatible with i.e. major.minor version 52.0


As per Wikipedia - Java class file the published numbers are:

Java SE 14 = 58 (0x3A hex)
Java SE 13 = 57 (0x39 hex)
Java SE 12 = 56 (0x38 hex)
Java SE 11 = 55 (0x37 hex)
Java SE 10 = 54 (0x36 hex)
Java SE 9 = 53 (0x35 hex)
Java SE 8 = 52 (0x34 hex)
Java SE 7 = 51 (0x33 hex)
Java SE 6.0 = 50 (0x32 hex)
Java SE 5.0 = 49 (0x31 hex)
JDK 1.4 = 48 (0x30 hex)
JDK 1.3 = 47 (0x2F hex)
JDK 1.2 = 46 (0x2E hex)
JDK 1.1 = 45 (0x2D hex)

As you have already mentioned in your question about using ...java jdk version7..., hence you see the error.


Solution

As the minimum requirement to compile org/openqa/selenium/WebDriver class file is Java 8 you have to upgrade JDK to the same level, preferably at current level of JDK 8u222.



来源:https://stackoverflow.com/questions/59670107/java-lang-unsupportedclassversionerror-org-openqa-selenium-webdriver-unsuppor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!