Showing posts with label how to install IEDriver. Show all posts
Showing posts with label how to install IEDriver. Show all posts

Saturday, October 20, 2018

First WebDriver Script on IE browser : Selenium WebDriver tutorial

Hi guys, In this post, I am going to discuss how to execute selenium script in Internet Explorer browser.


 Pre-requisite - 


  • Make sure you have already installed Eclipse IDE.
  • Make sure you have already configured WebDriver-jar file with your java project.
  • Make sure you have downloaded the latest version of WebDriver-jar file. Otherwise, you will get a compiler error.
  • Make sure you have downloaded the driver for Chrome. I will show you below how to do it. 



Note - If you don't know how to configureWebDriver-jar with your java project, then refer the link - Configure webdriver -jar files with Java Project





How to run Selenium WebDriver script in IE browser






1. Open Eclipse.

2. Create one Java Project for example SeleniumTutorial.






3.  Right click on SeleniumTutorial and navigate as shown below - 






4. Create one package lets say com.selenium and click on Finish.
5. In the same way, right click on com.selenium and create one class for example SeleniumTutorial.







6.  Finally, your class will be created and will be shown as - 











How to download IEDriver?

  • Refer the link - Download IEDriver
  • Download the latest version zip file based on 32-bit or 64-bit supported by your PC and also based on your OS. 




  • Open the downloaded file and extract it. It will look like - 
  • Open the extracted folder and then copy the path.


Now we will write the script 
  1. Under the main body, write - 

 System.setProperty("webdriver.ie.driver", "F:\software\IEDriver");  

Note - If you notice you are getting an error. The reason is that Eclipse IDE does not understand single '\'. So, we have to provide '\\' and append the provided path with the file name with .exe extension as shown below -



System.setProperty() has two parameters - 
  • First parameter - We pass the name of the driver.
  • Second parameter - We pass the path of the extracted jar file. 
     
     2. Next, write below statement - 

 WebDriver driver = new InternetExplorerDriver();  

Here, 'driver' is the reference variable of WebDriver Interface. An object of InternetExplorerDriver class has been created. 'driver' reference is referring to the InternetExplorerDriver object. Since the reference to the object of InternetExplorerDriver is assigned to 'driver', now 'driver' has control over the InternetExplorer browser.


Note - You will get two errors. We have used an Interface and a Class and as discussed above, an Interface and Class implementations reside in a particular package, we need to import those respective packages. If you hover over where the errors are showing, you will be suggested with some actions to perform. what you need to do is to import below two packages -


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

     3. We will open the Google homepage.

 driver.get("https://www.google.com/");  

Note:- get() - command is used to open a specific URL in the opened browser.

    4.  Now, we will close the browser.

 driver.close();  

Complete Code -


 package com.sessions;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.ie.InternetExplorerDriver;  
 public class SeleniumIE {  
      public static void main(String[] args) {  
           System.setProperty("webdriver.ie.driver", "F:\\software\\IEDriverServer_Win32\\IEDriverServer.exe");  
           WebDriver driver = new InternetExplorerDriver();  
           driver.get("https://www.google.com/");  
           driver.close();  
      }  
 }  

That all guys!!! 



Do comment in the comment box and share your views about the post. If you have any query, please comment on it. It will help me to reach to you and help you to resolve your query.