0

I have issue in my selenium script might be issue in Eclipse i tryed all possible aspect with adding all JAR library with different version but i faild to run script expert please look where i stuck

package Test;

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


public class Test {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver","C:\\Chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        String baseUrl = "https://www.facebook.com/";
        driver.get(baseUrl);
        WebElement email = driver.findElement(By.id("email"));
        WebElement password = driver.findElement(By.id("pass"));
        WebElement login = driver.findElement(By.xpath("//*[@id='loginbutton']")); 
        email.sendKeys("abcd@gmail.com");
        password.sendKeys("abcd123");
        login.click();
        System.out.println("Login Done with Click");    
    }
}

Error :

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
WebDriver cannot be resolved to a type

at Test.Test.main(Test.java:15)

This is my JAR library structure:

This is my JAR library

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
aasifghanchi
  • 102
  • 9

2 Answers2

1

This error message...

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
WebDriver cannot be resolved to a type

...implies that there were compilation issues in your program.

It is pretty evident from the snapshot you are using Selenium v3.6.0 but I don't see any error as such in your code block. However you can follow the below mentioned steps to solve the issue:

  • The Package name i.e. Test and the Class name i.e. Test needs to be different. You can't use the same name for the package and the class.
  • Upgrade JDK to recent levels JDK 8u202.
  • Upgrade Selenium to current levels Version 3.141.59.
  • Upgrade ChromeDriver to current ChromeDriver v2.46 level.
  • Keep Chrome version between Chrome v71-73 levels. (as per ChromeDriver v2.46 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • i Follow all update mention above script is still not execute gave `Could not find or load main class DemoPkg.TestCaused by: java.lang.ClassNotFoundException: DemoPkg.Test` this error – aasifghanchi Apr 24 '19 at 10:26
  • @DebajanB, this error is caused by i changed my dependency as per above solution here i stuck with one another error, and most important if i solved this error might be previous error arrived again how can i accept your answer without solving my problem – aasifghanchi Apr 25 '19 at 11:38
0

You need selenium-java on your classpath. The latest version at time of writing is 3.141.59.

selenium-java 3.141.59 (direct download)

All versions

Brian
  • 3,091
  • 16
  • 29