Selenium Webdriver Setup

Selenium Webdriver with Java and Eclipse Setup

Following steps will guide you through setting up selenium web driver on your machine-

Step.1. Configuring Java on machine
Download the latest version of the Java Development Kit(JDK) from here. Follow the steps mentioned to install JDK. We are installing JDK as it will be required for developing and running our automation scripts which are nothing but java programs.

Step.2. Download eclipse or any Java IDE of your choice
Download the latest version of the Java IDE you would like to use, for Eclipse the download link is Select the appropriate version of Eclipse depending on your system type- 34 bit or 64 bit.

In order to check your system type- go to my computer and right click and select ‘properties’, under system section you will see a ‘System type’ parameter. This parameter will define your system type.

Step.3. Download Selenium Webdriver jar from SeleniumHQ website
Go to SeleniumHQ website- and under “Selenium Client & WebDriver Language Bindings” download the web driver for Java.

Unzip the package and place it on any directory as a library folder.

Step.4. Creating a project and configuring selenium jars-

  • Launch eclipse.exe
  • Set your workspace to any location preferably other than C:(a workspace is a physical location where we store our project or group of related projects).
  • Now create a new project- File->New->Project…->Java->Java Project
  • Name your project and click Finish
  • Now you will see an src folder under your project. Under this we need to create a package-Right Click src->New->Package (Basically these packages are used to group together related classes). Name your package e.g. ‘myTestPackage’
  • Inside this package create a new class and name it e.g. Test, your class will get created


Step.5. Adding selenium jars
Right Click your project on the left and click on properties. A “Properties for {project name}” dialog box will appear. Click on “Java Build Path” on the left and then click on Libraries tab on the right. In this tab click on “Add External Jars..” button.

Now browse to the location where selenium libraries are placed(library folder Step#3). Make sure to add both the libraries-selenium-java-2.39.0.jar and selenium-java-2.39.0-srcs.jar along with the libraries present in libs folder(selenium-2.39.0\libs). The selected libraries will appear, click OK to add these libraries to your project. You can verify the same in the “Referenced Libraries” section under your project in the “Package Explorer” section on the left.

Step.6. Creating the first selenium web driver project
Time to test the setup. Now, we will create our first selenium project, in which we will just open the Firefox browser and launch a website. Following steps are required to launch the Firefox browser.

  1. Download geckodriver.exe from GeckoDriver Github Release Page. Make sure to download the right driver file based on your platform and OS version.
  2. Set the System Property for “webdriver.gecko.driver” with the geckodriver.exe path – System.setProperty(“webdriver.gecko.driver”,”geckodriver.exe path”);

Code snippet to launch Firefox browser-

public class FirefoxBrowserLaunchDemo {

    public static void main(String[] args) {
        //Creating a driver object referencing WebDriver interface
        WebDriver driver;
        //Setting webdriver.gecko.driver property
        System.setProperty("webdriver.gecko.driver", "{path to geckodriver}\\geckodriver.exe");
        //Instantiating driver object and launching browser
        driver = new FirefoxDriver();
        //Using get() method to open a webpage
        //Closing the browser

To run the test, right click on file on the Package Explorer section, hover over “Run As” and select “Java Application”. Firefox browser will launch and open SOFTWARETESTING.NET.

Was this article helpful?

Related Articles