i

Selenium Step By Step Guide

Working with Internet Explorer Driver - Part 3

Internet Explorer is one of the most used browsers for running the Selenium test cases. Let us discuss the steps to follow for configuring the Internet Explorer driver into our Selenium code:

  1. Set the property for the driver path.
  2. Set the Desired Capabilities and Instantiate the Internet Explorer driver object.
  3. Launch the URL using the driver object.

Set the property for the driver path:

String driverPath="C:\\Users\\IEDriverServer.exe";

System.setProperty("webdriver.ie.driver",driverPath);

Alternatively, we can set the driver path under “Environment Variables”, this way we can skip setting path from the code.

Select the Path variable section under System Variables and click on the Edit button. Now put a semicolon “;” at the end of the path variable’s string and enter the full path of the directory having Chrome Driver executable file.

 

Setting up the FirefoxOptions and DesiredCapablities and Instantiating the FirefoxDriver:

          DesiredCapabilities cap=DesiredCapabilities.internetExplorer();

        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);

        cap.setCapability("ignoreProtectedModeSettings",true);

        WebDriver driver=new InternetExplorerDriver(cap);

Launching the URL in chrome browser:

Now we have instantiated the ChromeDriver object and its time to launch the URL in chrome browser.

        driver.get("https://selflearning.io/");

 

Let us see the complete sample code to set up the chrome driver for running a Selenium script.

package SeleniumTest.SeleniumTest;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

public class IEBrowserTest

{

    public static void main( String[] args )

    {

                String driverPath="C:\\Users \\IEDriverServer.exe";

        System.setProperty("webdriver.ie.driver",driverPath);

        DesiredCapabilities cap=DesiredCapabilities.internetExplorer();

        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);

        cap.setCapability("ignoreProtectedModeSettings",true);

        WebDriver driver=new InternetExplorerDriver(cap);

        driver.get("https://selflearning.io/");

    } 

}