BreadcrumbHomeResourcesBlog How To Install Selenium WebDriver For Java October 25, 2021 How to Install Selenium WebDriver for JavaOpen Source AutomationBy Prakash VermaTesting modern complex applications can turn into a tedious task for a tester. To minimize these difficulties, an automation testing framework using Selenium WebDriver can help. By using this Selenium framework, testers can easily write their test cases efficiently and in less time. They don’t even have to know Selenium WebDriver in detail to do so.In this article, you will learn about installing Selenium WebDriver for Java installation, as well as what Selenium WebDriver is and why we should use it.Table of ContentsWhy Install Selenium WebDriver?Selenium WebDriver CapabilitiesHow to Install Selenium WebDriver Bottom LineTable of Contents1 - Why Install Selenium WebDriver?2 - Selenium WebDriver Capabilities3 - How to Install Selenium WebDriver 4 - Bottom LineBack to topWhy Install Selenium WebDriver?Selenium is an open-source tool used to perform automated testing on web browsers like Firefox, Chrome, Edge, Safari, etc. Selenium can only test web applications, so you cannot use Selenium to test any desktop applications.WebDriver is the most important Selenium component. It is a web framework that allows the tester to execute cross-browser testing. To create the test scripts, there is an option to choose a programming language, such as Java, JavaScript, Python, and C#/Ruby. Selenium WebDriver is designed in accordance with the client/server model. It communicates with the browser through the driver and data is communicated through the HTTP protocol. As long as the data format and protocol can be parsed by the server, WebDriver supports cross-platform, multi-language, and multi-browser.This WebDriver framework Architecture has four major components:1. Selenium Client library2. JSON wire protocol over HTTP3. Browser Drivers4. Real BrowsersThe functionality and usability of your software applications will determine your business growth. The same can be said for your web applications, because many businesses today rely on the Internet. Take any e-commerce company as an example. Whether it's Amazon or eBay or Flipkart, they all rely on customer traffic to their websites and business traffic on web-based mobile applications.Selenium WebDriver comes in before deployment, as an automated software testing tool that ensures your software is functioning and performing properly, to help your business grow.Back to topSelenium WebDriver CapabilitiesSelenium WebDriver is popular due to its capability to handle the testing work per the testing requirements. Some of the major features and benefits are listed below:1. Multi-Browser SupportSelenium WebDriver supports various Internet browsers, such as Chrome, Firefox, Opera, etc. Likewise, it also supports parts of unconventional programs such as HTMLUnit. HTMLUnit is a headless browser that does not use a GUI (graphical user interface).2. Various Language SupportWebDriver also supports a large number of languages commonly used in programming, such as Java, C#, JavaScript, PHP, Ruby, Pearl, and Python. Subsequently, the client can select any supported programming language according to its capabilities and start building test content.3. SpeedThe performance of WebDriver is faster when compared with different devices in the Selenium suite. It does not require any intermediate road workers to talk to the program; instead, the device directly talks to the program.4. Open-SourceSelenium is an open-source and portable web testing framework. This makes it free, and it also has a vibrant support community.5. Parallel Test ExecutionIt also supports parallel test execution, thereby reducing time and improving test efficiency.6. No Server InstallationThe Selenium Web driver does not require server installation, and the test script can directly interact with the browser.7. Easy Report GenerationWebDriver can be integrated with testing frameworks such as TestNG for application testing and report generation.8. Remote (and Local) Execution In addition to local execution, Selenium WebDriver enables remote test execution. This is the use of remote machines to run tests simultaneously and across a variety of test environments, such as operating systems, browsers, and system configurations. The ability to run test automation on numerous remote machines as well as multiple browsers is enabled with Remote WebDriver. This is especially helpful in a distributed setting where hundreds or even thousands of tests must be run on a regular basis. Back to topHow to Install Selenium WebDriver The process of installing Selenium WebDriver is made of many parts. We will go through:Installing Java on your computer system.Installing and configuring Eclipse. Eclipse is required to generate test cases.Installing the Selenium Java Client.Selenium WebDriver configuration.Installing Maven. Maven will take care of the build compilation, documentation, the creation of a correct project structure and the management of jar files in the project's build path.Creating a package.Step 1 - Installing Java Installing Java is comprised of three steps: -JDK InstallConfigure Variable EnvironmentJRE installIt might be confusing to understand why we need to both install JDK and JRE. So, let me explain the differences between them. JDK is used for developing testing and debugging apps and java applets. On the other hand, JRE provides libraries like JVM and other with the required components to run the applications which are written in java. Choose the correct one per your system requirement (as shown below in the image) and download the file. Just wait for a while as it downloads.Now, follow the instructions given below.By clicking on NEXT you will see a message stating that the JDK was successfully installed.In the image below you can see that both the JDK and JRE packages were installed together. This is a complete Java development kit.Setup - Environment Variable Search for “Advanced system setting” and open “System properties”. Click on Environment Variables. Under the system variables, you have to set the path for java. Click on the New button and write the new name of java variables. The variable name ( Java_Home_New), and the variable value will be the java path (you can see my path in the image below).After entering the variable name and variable value (path) and clicking on the OK button, you should get a screen like the figure below.To verify the version of java installed, open the command prompt and hit the command>> Java -version Step 2 - Installing Eclipse IDETo install Eclipse IDE, you first have to download the latest version of the Eclipse for Java EE (enterprise Edition) developer, because it is a complete package that will be useful for the Java standard edition. Download the link marked by the arrow sign in the figure below. (Make sure to make the correct choice between the 32-bit and 64-bit versions of Windows).After the installation process is completed, double click on the eclispse.exe file to launch Eclipse. Then you have to extract the zip file and run the application as administrator.Step 3 - Download Selenium Java Client DriverWe’re now ready to move on to installing Selenium!After you click the web page to download the Selenium WebDriver for the Java client, scroll down through the web page and locate the Selenium client and WebDriver Language Bindings. Click on the “Download” link of the Java client driver as shown in the figure below.The downloaded zip file named “selenium-3.14 zip” will be in a zip format. Unpack the contents in a convenient directory. It contains the essential jar files required to configure Selenium WebDriver in Eclipse IDE.Step 4 - Selenium WebDriver ConfigurationOnce Java and Eclipse are both installed the final steps are to configure Eclipse IDE with Selenium WebDriver. Configuring Eclipse IDE with Selenium Web DriverLet's see how to create a new Java Project in Eclipse.1. Launch Eclipse IDE: Launch the “eclipse.exe” file in the eclipse folder. In my case, the executable file is located at E:\eclipse\eclipse.exe.2. When the system asks to select a workplace, choose the default location.3. After clicking on OK, the Java Eclipse window will launch. Now, you can start creating a new project.4. To create a new project, go to file > New > Java Project. 5. Clicking on Java Project will open a new pop-up window. Enter the details as follows:Step 1 - Create the Project NameStep 2 - Enter the Path of the projectStep 3 - Select the execute environment JREStep 4 - Select project layoutStep 5 - Click on Finish6. After clicking on the Finish Button, the New Java Project starts showing with the latest version.Step 5 - Integrating Eclipse with MavenInstalling the Maven plugin for Eclipse will help manage your project. In many cases, the Maven plug-in is automatically installed in Eclipse. If it’s missing, go to Eclipse MarketPlace, search for Maven, and then download the M2E integrated version. Click on Install Now and then on the Confirm button:After that, the software will start installing and then Eclipse will restart.To create a Maven project, perform the following steps:1. Go to File -> New a Project2. Expand the Maven folder and select the Maven Project option, then click NEXT.3. Click the Next button once again to proceed.4. Select a Maven template type, give a group ID, and an Artifact ID. Automatically get a Java project with a correct project structure and a POM.xml when creating a project.5. If you already have an existing Java project, and after learning about Maven you want to change it to a Maven project, then just right-click on the project in the project explorer and select Configure -> Convert to Maven project.Step 6 - Package Creation Now we have to create a package under the new Java project (named “Selenium” in my case). 1. Right-click on the src file under selenium > New > Package, a pop-up window will open up.2. Enter the name of the package (here in my case name is “ doctech ” Note- use lower case).3. Click on the “Finish” ButtonNow we will create a new Java class under the new package (named “doctech”) by right-clicking on it and the go-to select New > class. The steps below will help you to create a new Class. 4. After clicking on Class, a pop-up window will open. Enter the following details:Create the name of the classClick on the “Finish” button When the Class has been created, the windows look like the image below.Now, we will “Build path” by right-clicking on “JRE system Library Java”. Follow the steps shown in the image:Then, follow these steps to add dependencies for Selenium:Right click on JRE system libraryUnder the properties dialog click on Java Build PathClick on the Libraries tabClick on Add external JAR to add external JARs.When you click on “Add External JAR”, a pop-up window will open and you have to browse the jar file from your given location and click on OPEN. Select two jar files like the below image shows:You will now see the jar files under the libraries tab:Add all JAR files outside and inside the libs folder:Click the OK button and finally, you have completed importing the Selenium library into your project!Yes, finally everything is set and you can start using Selenium. Back to topBottom LineIn this article, you learned about Selenium WebDrivers and how to install Selenium with Java. I hope you understood the concepts and that they added valuable knowledge to you.See how you can leverage Selenium through BlazeMeter. Start testing with BlazeMeter today.START TESTING NOW Related ResourcesDriving Headless Browser Testing with Selenium and PythonSelenium IDE vs WebDriver: Main Differences for Testers and DevelopersIntroducing Java 19 FeaturesIs Calling Java With Scala as Easy as It Seems?Back to top
Prakash Verma Data Scientist Prakash is a Data Scientist and Technical writer, with 8+ years of industry experience in software development and Testing. His primary experience includes Java, Selenium Testing, Python, Machine Learning, Cloud (AWS/Azure), and RDBMS.