Friday, 5 September 2014

Selenium C# : How to Open Internet Explorer Browser using selenium webdriver with ASP.Net C#

Click Here to Download OpenInternetExplorerWithSeleniumWebDriverTool.zip

Note : If any runtime error occurred by running our downloaded project meaning of that your browser version and Selenium API DLL version is not matching. To resolve this issue you need to download latest Selenium C# API DLLs from this link and paste downloaded DLLs into 'Bin' folder of downloaded project. Or you can remove references of existing DLLs references and add new DLLs references. You can learn this thing from this link.


We can also open Internet Explorer Browser programmatically using selenium 'WebDriver' API with ASP.Net C#.

In previous article we learned How to Open Firefox Browser using selenium 'WebDriver'.

For opening or launching Internet Explorer (IE) is different from Open FireFox. In that we need one extra EXE file named 'IEDriverServer.exe' file and also set 'IE' Options object to give Startup URL.

If you Do not have 'IEDriverServer.exe' file file at that time Code gives us an error like :
The IEDriverServer.exe file does not exist in the current directory or in a directory on the PATH environment variable.

But basically it is very simple.

Here are steps to learn How to Open IE Browser :


STEP 1 : First create new 'WebSite' after creating new 'WebSite' add new page. On this previous article your learn this.

STEP 2 : Now, you need special Executable (EXE) file named "IEDriverServer.exe". You can download this file from this URL :
http://selenium-release.storage.googleapis.com/index.html. You can choose latest version folder on this link. Or you can also get this file from our project zip file, In our project we have both 32 and 64 bit zip file. You can get that file from zip file.

STEP 3 : After downloading file, Add new folder in your website or project named it 'EXEFiles' and copy your downloaded file 'IEDriverServer.exe' in this folder.

STEP 4 :  Open your new page code file like 'Default.aspx.cs' file. Import selenium 'namespaces' and write following code on 'Open Internet Explorer Browser' button click event.

Code File :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Selenium;
using OpenQA;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnOpenIEBrowser_Click(object sender, EventArgs e)
    {
        string STR_IE_DRIVER = Server.MapPath("EXEFiles"); //Set Path for EXE file

        var objIEOptions = new OpenQA.Selenium.IE.InternetExplorerOptions() // Set Options
        {
            InitialBrowserUrl = "www.google.com",
            IntroduceInstabilityByIgnoringProtectedModeSettings = true
        };

        //Create object for open IE
        OpenQA.Selenium.IE.InternetExplorerDriver objFF = new OpenQA.Selenium.IE.InternetExplorerDriver(STR_IE_DRIVER, objIEOptions);
    }
}

Explanation : In this code you can see that First we set path of 'IEDriverServer.exe' file, in which folder we save this file. After that, we create object of 'InternetExplorerOptions' class and set properties like 'InitialBrowserUrl' and 'IntroduceInstabilityByIgnoringProtectedModeSettings'.

This 'InitialBrowserUrl'  property use for By default when IE open this URL is open in IE. After that, we create object of 'InternetExplorerDriver' class to open IE. You can see that in constructor of 'InternetExplorerDriver' class we supply 'IE_DRIVER' Path and 'IE OPTION' object.

STEP 5 : Run the website. After Default page is appeared in browser, this website may run in any browser. You click on 'Open Internet Explorer Browser' button. It will Open Internet Explorer Successfully.

[Image : Run Website and open Page] :

Selenium C# : How to Open Internet Explorer Browser using selenium webdriver with ASP.Net C#
(To view original size image , click on image)

[Image : Internet Explorer Opened] :

Selenium C# : How to Open Internet Explorer Browser using selenium webdriver with ASP.Net C#
(To view original size image , click on image)


Full Video : 



2 comments:

  1. really well said about How to Open Internet Explorer Browser using selenium webdriver with ASP.Net C# keep share interesting article on selenium

    Selenium Training Institute in Chennai

    ReplyDelete
  2. Great article!!!!!This is very important information for us.I like all content and information.I have read it.You know more about this please visit again. Best Hadoop Training | Hadoop Online Training

    ReplyDelete