WebDriver Cannot be Resolved to a Type [Solved]

Check for missing JAR files

by Kazim Ali Alvi
Kazim Ali Alvi
Kazim Ali Alvi
Author
Kazim has always been fond of technology, be it scrolling through the settings on his iPhone, Android device, or Windows PC. He's specialized in hardware devices, always ready... read more
Affiliate Disclosure
  • To fix the WebDriver cannot be resolved to a type error during compilation, add the JAR files under Classpath instead of Modulepath.
  • Keep reading to find the step-by-step solutions recommended by our experts!
fix webdriver cannot be resolved to a type

The WebDriver cannot be resolved to a type or ChromeDriver cannot be resolved to a type errors encountered when running a script highlight compilation issues. This is usually due to missing Selenium jar files, but a misconfigured path or similar problems can also trigger the error!

How do I fix the WebDriver cannot be resolved to a type error?

Before we start with the slightly complex solutions, try these quick ones:

  • Restart the device and try again.
  • Change the Java Compiler’s compliance level to 1.8. Also, you may try the other available options.
  • Check if you are missing the selenium-java-2.53.0-srcs.jar and selenium-java-2.53.0.jar files from Selenium 2.53.0. These are not included in lib but must be included manually from the same folder.

1. Add Selenium jar files to ClassPath

1.1 Download the JAR files

  1. Go to Selenium’s official website, and download the language-specific client drivers for Java.java download
  2. Now, locate the downloaded .zip file, right-click on it, and select Extract All.extract all
  3. Go with the default extraction path and click the Extract button. To change the path, click on Browse and set a new one.
  4. Now, move the extracted files to the preferred location.

1.2 Adding the JAR files

  1. Right-click on the project in the navigation pane, hover the cursor over Build Path in the context menu, and select Configure Build Path.configure build path to fix webdriver cannot be resolved to a type
  2. In the Libraries tab, expand the Modulepath entry, select all the files listed here, and click the Remove button.
  3. Now, select Classpath and click on Add External JARs.add external jars to fix webdriver cannot be resolved to a type
  4. Navigate to the path where the downloaded JAR files are stored, hold the Shift key, then select them all, and click on Open.
  5. Once done, click on Apply and then Apply and Close for the changes to come into effect.apply and close

When compiling Selenium projects in Java, you need to add the Selenium Jar files. While doing so, make sure to get the latest stable version and also include jar files from the lib folder.

2. Change the path

When adding the property, many users miss out on the lowercase and have parts of it in uppercase instead. Also, the path must include chromedriver as chromedriver.exe.

So, if you currently have the property as (the path is just for reference, Username is the active profile name): System.setProperty("Webdriver.Chrome.driver","/C:/Users/Username/Downloads/chromedriver_win321/chromedriver");

Change it to: System.setProperty("webdriver.chrome.driver","C:/Users/Username/Downloads/chromedriver_win321/chromedriver.exe");

This should fix the WebDriver cannot be resolved to a type error. Also, it works for ChromeDriver and Firefoxdriver since the idea remains the same.

Before leaving, find out how to run JAR files in Windows and you will be able to develop codes seamlessly.

For any queries or to share what worked for you, drop a comment below.

This article covers:Topics: