How to Install Selenium Webdriver in Eclipse
Hello there! We are gonna look at How to Install Selenium Webdriver in Eclipse hereby which is one of those crucial stepping stones when you are looking into the world of Selenium. That being said, how to install selenium Webdriver in Eclipse involves the following steps:
- Downloading Eclipse for Windows
- Installing it of course
- Integrating Selenium jar files into your Eclipse IDE.
We are moving forward with our Selenium lessons. That means it’s progress. Let’s keep up the speed because there is so much to learn and we haven’t started properly really.
We gotta configure Selenium at once so that we know at least how Selenium Webdriver looks, right? I have no idea so far how things appear in reality.
Together we shall find out, and I promise to drop an emoji of a surprised look when we do.
I hope you have Java installed on your system already. If you haven’t then you can read our Java Chapter that teaches you how to do that first. Please install Java ASAP before proceeding, since our future interactions are going to be strictly in Java.
So without wasting any more time, we are going to dive into learning how to install Selenium Webdriver in Eclipse which, as a matter of fact, will pave way for future Java codes and Selenium things to be understood by Eclipse.
Install Eclipse IDE
You got to install Eclipse first in order to learn the configuration of Selenium. If you want to learn how to install Eclipse IDE I have made you a simple step by step process here:
Installing Eclipse IDE in Windows
Once you are done with that, come back here.
Want to take a break?
Alright, I am going to the loo.
Downloading Selenium Jar Files
Now comes the tricky part. Not the loo of course. That was the easiest!
Here’s where you come across to Selenium Webdriver for the first time.
What is Selenium Webdriver, you ask?
It is nothing but a collection of Java libraries with some predefined methods of its own. Installing it in Eclipse will help it understand where to look for files when it encounters your fancy words it doesn’t know anything about.
For that, you need just some Selenium Jar Files. Here’s what you need:
- Selenium Remote Standalone Server
Step 1: Go to the following link:
http://docs.seleniumhq.org/download/
Step 2: You need a Selenium Standalone Server basically for Eclipse to understand what Webdriver classes are all about.
Click on Previous Releases on the left-hand side of the page.
When you click on the Previous Releases button the index of / page should display.
Step 4: Click on the latest version. Herein it says 3.2
Click on the server standalone 3.2.0 jar file and download the jar. Place it in a folder you can remember.
A simple task of how to install Selenium Webdriver in Eclipse conquered.
How to Install Selenium Webdriver in Eclipse
Once you are done downloading the jar file, it is time to configure Eclipse to work with Selenium Webdriver. To do that you need to first create a Java Project.
Creating a Java Project
All you gotta do is open Eclipse first.
Step 1: Click on File> New> Java Project
Step 2: You will find a New Java Project dialog box pop up. Give the project a name. Call it whatever you want to call it. I am gonna name mine GameofThrones for the heck of it. When you click on Ok it begins to show on the left side of your screen.
Adding a Package to your Project
Step 3: Right click on your GameofThrones project, and then on New > Package. Remember that’s how you always create packages around in Eclipse. In fact, right clicking on your project and then on New is how you get all the options of creating Class, Interface, Enum and what not.
Here we are going to stick to packages.
Step 4: Give a name to your package. I am gonna call mine housestark.
Creating a Java Class
Step 5: Now it’s time to create your first Class. Right click on the package “housestark” now and then on New> Class.
Step 6: On clicking on Class you will get this dialog box that will ask you to enter a name for the class. Don’t worry about the rest of the things, we will try cover them all under our Java category. If you know things already, then there is nothing to worry about.
I am going to name my class “NedStark”.
NOTE: If you check the box that says public static void main (String[] args), it will automatically add it in your Java class file. Go ahead and click it before clicking on Finish.
When you click on Finish you will notice how you get a page that comes with with pre-written stuff. The package that you had entered (housestark) has been automatically added to your .java file. Also, you will notice how your class name (NedStark) has been appended to the same file, and a precursor of “public class” has been added against it. Even public static void main something you had checked on the above dialog box begins to reflect which is pretty cool.
Chill! That’s the beauty of Eclipse. It saves you the trouble of writing things manually.
Adding all the Selenium Jars
That takes us to the final step of learning how to install Selenium Webdriver in Eclipse.
Check your watch!
Now is the right time to add the jar file.
Step Are you still counting?
Right Click on your project (GameofThrones) and then on Build Path > Configure Build Path.
I don’t know why I am humming the Game of Thrones addictive title song.
Okay, so clicking on that will open a dialog box that says Properties of GameofThrones.
Step 8: Click on the Libraries Tab and then on the Add External JARs… button.
Step 9: Notice how a JAR selection dialog opens. It’s prompting you to select that Selenium standalone jar file you had downloaded earlier.
Look for your file where you had extracted file selenium-server-standalone-3.2.0. Grab the file and click on Open.
So the final display should be something like this:
Click Ok when you are done.
All the JAR files have been added to your project. You can check them out by clicking on the Referenced Libraries tab on the left side of your Eclipse. Their will be tons of libraries imported, any of whose classes you can access using the import package command.
:-O
That’s it!
Selenium Libraries have been imported to your project “GameofThrones” now.
Ta-da!
You have just understood how to install Selenium Webdriver in Eclipse.
Webdriver Script Example
How are we now? All good?
Why surly? Not sure?
Alright, then why don’t you just copy paste the following code in that Java file and Run. Do not actually run! Just run the file dude.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class NedStark { public static void main(String[] args) { System.setProperty("webdriver.ie.driver", "pathofyourexedriver\\IEDriverServer.exe"); InternetExplorerDriver driver = new InternetExplorerDriver(); driver.get("http://google.com"); System.out.println(driver.getTitle()); driver.close(); } }
The above code is supposed to open Internet Explorer run google.com site and then grab the title of Google and show it to you.
Make sure you replace the pathofyourexedriver with the precise location of IEDriver.exe file which you can download from here:
http://www.seleniumhq.org/download/
Here’s the precise thing that you have to click, even though your OS is 64 bit, there are some issues with 64 bit Windows IE.
Alright so when you execute the above what the code is supposed to do is basically open a new Firefox window, then open the Google link on it. It would then grab the title from it displaying it and then eventually close the window.
Word!
Importing Selenium Libraries have been overcome. You have now successfully learnt how to install Selenium Webdriver in Eclipse. We shall look how to work around with Selenium in the next chapters. Till then take a vacation or something. I know you have been knackered.
1 Response
[…] There are browser specific drivers entailed here that sends or retrieves commands from a browser. An example of which we saw in the “Installing Selenium Webdriver chapter“. […]