Selenium WebDriver - IE [Internet Explorer] browser

Selenium WebDriver - IE [Internet Explorer] browser

In this segment, we will understand how to run a test script with the help of the IE (Internet Explorer) browser.

It is a standalone server that is used to implement the WebDriver’s wire protocol. And it is a link between our tests in Selenium and the Internet Explorer Browser.

We need to have an IEDriverServer.exe executable file to run our test script in the IE browser.

The above executable file starts a server in our local system to run the Selenium WebDriver test scripts.

We will create a test case in the same test suite (new_test), which we created in the previous tutorials.

Step1:

  • Firstly, we will right-click on the src folder and create a new Class File from NewClass in the Eclipse IDE.
Selenium web driver - IE Internet Explorer browser
  • And give your Class name as Test_IE and click on the Finish button.
Selenium web driver - IE Internet Explorer browser 1

Step1:

  • Go to the selenium community and download the IE driver server.
Selenium web driver - IE Internet Explorer browser 2
  • Download the folder to your local system. Unzip the folder and make sure that you downloaded the specified version of IE drivers like 64 bit or 32 bit.
Selenium web driver - IE Internet Explorer browser 3
  • Run the server before launching the IE browser, with the help of System.property.

Syntax:

 System.SetProperty(“key”,”value”);

Where,

Key = “webdriver.ie.driver” 

And then copy the path of the IE driver server to invoke the IEDriver class.

Value= “C:\\Users\\JTP\\Downloads\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe”

Here, is the sample code to set the system property,

// System Property for IE Driver   
System.setProperty("webdriver.ie.driver","C:\\Users\\JTP\\Downloads\\IEDriverServer_x64_2.480\\IEDriverServer.exe");
// Instantiate the IEDriver class
WebDriver driver=new InternetExplorerDriver();   

Now, let us see one sample test case, in which we will try to automate the following scenarios in the IE browser.

Steps Action Method Used Input Excepted Result
1. Open the IE Browser. System.setProperty()   The IE browser must be opened.
2. Navigate to the Given URL of the website. get() https://www.google.com/ The home page window must be displayed.
3. Maximize the browser.     The browser window should be maximized.
4. Identify the Google search button and type Gmail after that click on the search button.   The search button should be identified, and the value should be entered.
5. Close the Browser. close()   The browser should beterminated.

Here is the sample code for the above example,

package testpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.ie.InternetExplorerDriver; 
public class Test_IE {
public static void main(String[] args) throws InterruptedException { 
// System Property for IEDriver
System.setProperty("webdriver.ie.driver", "C:\\Users\\JTP\\Downloads\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe");
// Instantiate an IEDriver class.
WebDriver driver=new InternetExplorerDriver();
// invoke the URL
driver.get("http://www.google.com/"); 
//Maximize the window browser 
driver.manage().window().maximize(); 
// Click on the search text box and pass the value 
driver.findElement(By.name("q")).sendKeys("gmail"); 
Thread.sleep(2000); 
System.out.println("value is passed");
// Click on the search button  
driver.findElement(By.name("btnK")).click(); 
System.out.println("button is clicked");
//close the browser
driver.close(); 
}  
} 
  • Now, right-click on the Eclipse code, and select Run As ? Java Application.
  • When we run this code into the IE server, we may face some challenges, and show the NoSuchSessionException exception.
Selenium web driver - IE Internet Explorer browser 4

To resolve the above exception, we have made some changes.

Before running the web driver code, the below settings should be done in IE Browser:

Browser zoom level should be 100%:-

  • Click on the Setting button, which is present on the right corner of the browser.
  • Then move your cursor to the zoom tab and set the zoom level at 100%.
Selenium web driver - IE Internet Explorer browser 5

Security level for all the zone should be the same:-

  • Go to the tools, then select the Internet Option and go to Security.

Tools ? Internet Options ? Security

Selenium web driver - IE Internet Explorer browser 6
  • For this, we should enable the protect mode checkbox selected for all the zone.
Selenium web driver - IE Internet Explorer browser 7
  • Now re-run the test script and see the output in the IE browser.
Selenium web driver - IE Internet Explorer browser 8

There is one more issue,

 While running a test script in 64-bit window platform:-

  • The speed of the passing value in the search box is typing an alphabet one by one.
  • Not getting any further speed issues in the IE browser, we will run our test script in the 32-bit window platform.
  • To run the test script in the 32-bit version, follow the same process, and download the 32-bit version instead of 64-bit.
Selenium web driver - IE Internet Explorer browser 9
  • Then, download the folder to your local system and unzip the folder.
Selenium web driver - IE Internet Explorer browser 10
  • And do changes in the system property‘s value portion of the IE server in the above code.

Value= “C:\\Users\\JTP\\Downloads\\ IEDriverServer_Win32_3.14.0\\IEDriverServer.exe”

The new system property will be look like this:

// System Property for IE Driver (32-bit)
System.setProperty("webdriver.ie.driver","C:\\Users\\JTP\\Downloads\\IEDriverServer_Win32_3.14.0\\IEDriverServer.exe"); 

The output of all print command of the above test script would be displayed in the Eclipse console window.

Selenium web driver - IE Internet Explorer browser 11