How To Run WebDriver Script In Chrome And Internet Explorer

In Selenium WebDriver, if you want to run your script in Chrome then you need to do a few downloads and setting up of path and the driver. The very first step is downloading of chrome driver. You need to download the chrome driver to your local system first. Once you have the chrome driver in your system, you can easily set up the driver in the script by providing its path of your local system.

Now you have the chrome driver exe file. Go to eclipse, create a java project and a package under that project. Then create a class and write the following code into it :

package home;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class demo {

public static void main(String[] args)
{

System.setProperty(“webdriver.chrome.driver”,”D:\\chromedriver_win32

\\chromedriver.exe”);

WebDriver driver=new ChromeDriver();
driver.get(“http://www.google.co.in/”);

}

}

In the above code we have added a line System.setProperty(“webdriver.chrome.driver”,”path of the chrome driver“), This line has been added to set up the driver. If you don’t add this line of code into your script, then this code will trough some error stating some driver problem. This line of code is not required if you are writing your script for Firefox browser. But if you want to run your script in Chrome, then this line i.e; setting up of driver is necessary.

6

It was for chrome if you wish to run your webdriver script in chrome. Likewise, if you want to run your webdriver script in IE, then you have to follow the same procedure.

The first step you need to take is download the IE driver. Go to http://www.seleniumhq.org/download/ and download the IE driver by clicking on the below highlighted link :

8

Once you download the IE driver, keep it somewhere in some drive of your local system. This path for the driver you have to pass in your webdriver script. The code you need to add is :

package home;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class demo {

public static void main(String[] args)
{

System.setProperty(“webdriver.ie.driver”,”D:\\IEDriverServer_Win32_2.44.0\\

IEDriverServer.exe”);

WebDriver driver=new InternetExplorerDriver();
driver.get(“http://www.google.co.in/”);

}

}

Here the line System.setProperty(“webdriver.ie.driver”,”path of the IE driver in your local system“); is to set up the driver. So the basic thing you need to do for running your script in IE is download the IE driver and pass its path to this line of code and then execute.

One thing you should keep observe is while writing the script for chrome we write “webdriver.chrome.driver” inside the setProperty and while writing the script for Internet Explorer we need to write “webdriver.ie.driver” .

7

This was all about running your webdriver script in chrome and Internet Explorer.

Add Comment