Tuesday, 2 September 2014

Selenium Webdriver : How to Open Firefox Browser using selenium webdriver with ASP.Net C#

We can open FireFox Browser programmatically using selenium webdriver API with ASP.Net C#. Here you can Learn how to open Firefox browser using selenium webdriver with ASP.Net C#

STEP 1 : First you need to create empty 'Website' or in existing 'Website' or project you need to add selenium 'WebDriver' API DLL references.
You can visit this link to create new 'Website' and add selenium 'WebDriver'API DLL references.

Selenium Tool : Download selenium Webdriver for ASP.NET C#.
Selenium Tool : Configure selenium tool for asp.net C# website or project in Visual Studio.


STEP 2 : Add new Blank page and add Command Button. We will open FireFox browser on click of this command button. Give button 'ID' like 'btnOpenFF' and set Text property as 'Open FireFox Browser'.

Below is full HTML of this page :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button runat="server" ID="btnOpenFF" Text="Open FireFox Browser" OnClick="btnOpenFF_Click" />
        </div>
    </form>
</body>
</html>

[Image : HTML Page File] :

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


STEP 3 : Go to the code page of this file and import Selenium Webdriver 'namespaces'. Namespaces are 'Selenium' and 'OpenQA'.

Write below code to import 'namespace' :

using Selenium;
using OpenQA;

STEP 4 : Now on click event of our new added command button Create object of 'FireFoxDriver' class. This created objects automatically Open or Launch FireFox browser when this code is executed.

Here is Button click event code :
    protected void btnOpenFF_Click(object sender, EventArgs e)
    {
        OpenQA.Selenium.Firefox.FirefoxDriver objFF = new OpenQA.Selenium.Firefox.FirefoxDriver();
    }

Here is full page code :
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 btnOpenFF_Click(object sender, EventArgs e)
    {
        OpenQA.Selenium.Firefox.FirefoxDriver objFF = new OpenQA.Selenium.Firefox.FirefoxDriver();
    }
}

[Image : Code Page Image] : 

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

[Image : Run Website] : 

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

[Image : Click on 'Open FireFox Browser' Button and It will Open Browser] :  

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


Full Video : 


No comments:

Post a Comment