In the previous page, we learnt how to install Selenium IDE plugin our Firefox browser. Now let us take a look at another component of the Selenium Suite- the most powerful one- Selenium Webdriver.
Selenium Webdriver allows you to control the browser interactions- using various methods , which we generally call as API’s. The best thing about Webdriver is that is gives the freedom to control and mimic almost all kinds of user interactions, in the best possible way and without the restriction of a programming language. Selenium Webdriver bindings are available for Java, Perl, Python, Groovy, C#, Ruby etc.
Here I would be demonstrating how we would use an IDE- like Eclipse and set- up Selenium Webdriver set up for Java language using the Java API’s.
The first thing we would like to install is an IDE like Eclipse – I am basing this on the assumption that you know what Java is and have a fair amount of idea about it. That is why I have skipped the Java installation part.
Installing Eclipse IDE
- Open up your web browser and search for Eclipse or simple Google -“Eclipse Download. Click on the link which comes up in the search.
- Once you open up the Eclipse download page, you will see a lot of options for download. Do not select the Eclipsee IDE for Java EE developers. That is the most common mistake that I have seen people do. Select the first option (it will be for Eclipse Luna). Select the version- 32-bit or 64-bit version according to your OS configuration.
- Eclipse download page gives you the option to select the download mirror. You needn’t change anything here. Just click on the green button and the download will start.
- Thank You page comes up. Your download will start shortly.
- Once the download completes, you’ll see the .rar file of the Eclipse downloaded in your system.
- Extract this file in the same folder. Open the folder. You will see these things in the folder.
- Click on the Eclipse icon. It will ask you for the Workspace location, where it will store and keep all your program files. If you don’t have Java installed on your system, then Eclipse will throw an error, before opening up the workspace location. So make sure you have Java installed.
Once you click the Ok button. Eclipse will take a minute to set up everything and then the IDE window comes up. This completes the installation of Eclipse IDE on your system.
Downloading Selenium Jar Files
We need the selenium jar files, which will allow us to use the powerful features of Webdriver API. Since our choice of language is Java, we need to download the JAR files, from Selenium home page.
- Open your browser and search “Selenium installation” in search box.
- We download the Java implementation. Click on the link. The jar files will start downloading. It’s around 23-24 MB in size. Allow it to download.
- Once the download completes, you’ll see the .rar files for Selenium 2.44.0 in your download folder. Extract the into the target folder you want. You can extract in the same driver as well. It doesn’t matter.
We have now downloaded and extracted Selenium jar files in our system. Now we need to integrate Selenium in our project in Eclipse. Open up the Eclipse window.
- Open the Eclipse window. Go to top left hand corner and go to File -> New -> Project
- Select “Java Project” from the options that comes up in the next window.
- Enter a name for your project. Leave all other things untouched here. No need to change anything. Keep them as they are by default. Click on Next button here.
- In the next window, you needn’t do anything. Just click the FINISH button.
- Pressing the FINISH button creates a new entry in the Package Explorer section of the window. It should be showing a new entry with the name you chose for your project.
If you click the “+” sign, it will be something like this.
Your project has been created. Now we need to add Selenium jar files to this project.
Adding Selenium To Your Project
Now that we have downloaded Eclipse, created a project and downloaded Selenium jar files, it’s time for us to add these jar files to our created project.
- Go to the Project folder and right click on the “src” folder. Out of the various options available, go to Build Path.
- Once you go to Build Path, another menu opens up. Now select Configure Build Path from those options.
- The java Build Path opens up. You will see four different tabs. Now Select Libraries tab from those tabs.
- Go to Add External Jars button. Since Selenium doesn’t comes embedded into eclipse, we need to add those external jars manually here, in our project build path.
- This will take you to the download folder in C. You need to go to the location where you have downloaded and extracted the Selenium jar files. For me it is C:/Downloads/Compressed.
- Search for Selenium 2.44.0 folder. And open it. You’ll see two files in that folder. Select those two files and click on Open.
- Clicking Open will add those two files in the Java Build Path.
- Now go back to the Add External Jars button. Click again. This time click on the lib folder present.
- You will see a lot of jar files here. Press Ctrl+A and select all the files. Click Open.
- All the selected files are now added in the Java Build Path. This completes adding the Selenium jar files to your project.
- In the Package Explorer, you will see Referenced Libraries. Click on the “+” sign.
- All the added Selenium files are shown in this folder. This means you have successfully added the Selenium jar files in the Project. Now you will be able to use the Selenium API in your programs.
Selenium is now added to your project. Let us start by writing few programs. Click here for a simple sample code.is
This installation is for Windows systems. And uses Java as programming language. Now a days, Python is increasingly gaining popularity among testers for use in Selenium. Check this for a instructions on how to use Selenium with Python on a linux machine.