Selenium provides its API implementation in multiple programming languages. However, Selenium API Java-based bindings are the most popular. In this tutorial, we will learn how to download Selenium JARs and configure Eclipse IDE to use them in writing test scripts. To configure Eclipse with Selenium WebDriver, we need to perform the following activities:

  1. Installing Java
  2. Installing Eclipse IDE
  3. Configure Eclipse IDE with WebDriver

Installing Java

selenium illustration for: Installing Java
  • Step 1: Go to the official website (https://www.oracle.com/technetwork/java/javase/downloads) and click on the Download tab.
  • Step 2: Click Icon under Java SE Downloads
  • Step 3: Accept the License Agreement and choose the JDK that corresponds to your Operating System.
  • Step 4: Once the download is complete, run the executable file to install JDK in Windows. Perform similar steps for Mac DMG file. For Linux, you just need to untar and set PATH variable to execute java commands.

There has been a major change in the Java Licensing from Java 11 onwards. For commercial purpose, Oracle JDK is not free anymore. However, you can use OpenJDK, which is absolutely free to use in production environment. Read more about it at [Java 11 Features](/community/tutorials/java-11-features).

Installing Eclipse IDE

Let's see how to install Eclipse IDE for Windows. The steps are almost similar for Mac and Linux operating systems too. You have to follow similar steps with the Eclipse installer files of the corresponding operating system.

  • Step 2: Once the download is complete, run the exe file to start Eclipse installer application for Windows.
  • Step 3: Click "Eclipse IDE for Java Developers" in the installer window.
  • Step 4: After that, a new window will open. Change the Installation Folder path to "C:\eclipse" and click on install button.
  • Step 5: After successful completion of installation, a new window will open. Click on the Launch button in the new window.
  • Step 6: This will launch Eclipse IDE for you. From next time onwards, you can start Eclipse from its installation folder.

Selenium JARs Download

Basically, selenium is not installed, it is configured. We just need to download the jars and include in eclipse.

  • Step 2: Click on Download link to download the jars for selenium.
  • Step 3: Extract the downloaded folder and we will get the folder like selenium-java-3.141.59.

Configure Eclipse IDE with Selenium WebDriver

  • Step 1: Launch the "eclipse.exe" file inside the eclipse installation folder.
  • Step 2: When asked to select for a workspace, just click Launch button to accept the default location.
  • Step 3: Create a new Java Project from _File > New > Project_.
  • Step 4: Give your Project name ‘_Testing_‘ as shown below. Click on _Finish_ button.
  • Step 5: _Right click_ on Project name _Testing_ and select _New > Package_.
  • Step 6: Give Package name _automation_ and click on _Finish_ button.

Now you can see a new package name _automation_ under project name _Testing_.

  • Step 7: Right click on package _automation_ and select _New > Class_.
  • Step 8: Give Class name _Test_, check the option checkbox _[public static void main](/community/tutorials/public-static-void-main-string-args-java-main-method)_ and click on _Finish_ button.
  • Step 9: Now your Eclipse window will look something like below.
  • Step 10: Now we add few lines of Selenium code without adding JAR files. Below image shows us the error message when we won't add jar files.

Let's go ahead and add Selenium JAR files to our project to fix these errors.- Step 11: Right click on Project _Testing_. Select _Properties > Java build Path_. Then click on _Libraries_ tab and click _Add External JARs_.

  • Step 12: Add client-combined jar from the selenium jars folder.
  • Step 13: Add all the jars under _libs_ folder.
  • Step 14: Click Apply and Close button.
  • Step 15: Now your Project Package Explorer window should look similar to the below image. Also, the errors related to Selenium classes would have been disappeared. Here we need to import WebDriver and ChromeDriver classes.

That's it. Our Eclipse Java project is configured to use selenium classes.

Selenium Maven Dependencies

Most of the java project these days use Maven as the build tool. In that case, it's very easy to import selenium jars into your project. Just add the following dependencies into your project pom.xml file.

				
					<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>  
				
			

If you are new to maven project, here are the steps to follow.

  • Step 1: Open Eclipse then go to _File > New > Project_.
  • Step 2: In the new project window, there are many wizard to choose. Select Maven Project under Maven category and click on Next button.
  • Step 3: Click on Next button in the new screen. Don't forget to select the "Use default Workspace location" option.
  • Step 4: Select the maven-archetype-quickstart in the next screen and click on Next button.
  • Step 5: Enter _Group Id_, _Artifact Id_ and click on _Finish_ button.
  • Step 6: Once the project is created you can see the maven project in the project explorer.
  • Step 7: Double click on pom.xml and you will get the source code of pom.xml in the editor.
  • Step 8: We need selenium maven dependencies configuration to add to our project. Head over to _https://www.seleniumhq.org/download/maven.jsp_. Here Selenium guys have provided maven dependency information. Just copy them as we need to paste it in pom.xml file.
  • Step 9: Open pom.xml file and create _<dependencies>_ tag and paste the dependency code inside it. Save the pom.xml file changes.

!Maven DependenciesSelenium Maven Dependencies[/caption]– Step 10: Check your project "Maven Dependencies" to confirm that selenium jars has been downloaded and included in the project. !Maven Project Dependencies

Selenium Gradle Dependencies

Gradle is also a popular build tool and used by a lot of projects. If you are using Gradle, then add below dependencies to your build.gradle file.

				
					compile "org.seleniumhq.selenium:selenium-java:3.141.59"
				
			

Summary

We learned how to configure our system to start working with Selenium. We installed Java, Eclipse and created a new project and added selenium jars to it. However, it's better to use Maven or Gradle build tools for our project, we also learned how to add Selenium jars using maven and Gradle script. References: Java SE Download, Eclipse Download,Selenium Jars