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)

Thursday, 28 August 2014

Selenium Tool : Download and Install WebDriver Element Locator Add-on

Element Locator Add-on is available in FireFox Browser as Add-on or extension. You can install it in FireFox browser.

Element Locator Add-on is very useful to find or locate appropriate web element or control like, text box, button, image, input box, etc. in browser. It will return location string of that particular control. This string is helpful in selenium automation process.

When you right click on particular control or element in Firefox browser, it will populate context menu with very useful XPATH for 'WebDriver' which is very useful in 'findElement' method of selenium 'WebDirver' API.

Here are steps to download and install 'WebDriver' element locator.

STEP 1 : Go to FireFox add-on link :
FireFox Add-on URL : https://addons.mozilla.org/en-US/firefox/addon/element-locator-for-webdriv/?src=api

[Image : Open Add-on URL] :
Download and Install WebDriver Element Locator Add-on
(To view original size image , click on image)

STEP 2 : Install :
After opening this URL you can see one 'Add to Firefox' button, click on this button, it will open one dialog box and ask you for Install, Click on 'Install' button, after that Add-on is installed and give a successful installation message. You can also check in 'FireFox' add menu, for that go to Menu, Tools -> Add-Ons, here you can find list of installed add-ons.

[Image : Install Now] : 
Download and Install WebDriver Element Locator Add-on
(To view original size image , click on image)

[Image : Install Successfully] :  
Download and Install WebDriver Element Locator Add-on
(To view original size image , click on image)

[Image : Element Locator Context Menu] : 
Download and Install WebDriver Element Locator Add-on
(To view original size image , click on image)

After installation, open any URL and do right click on any element you can see the various menu items like C# Locator, XPATH, etc. In this, you can find various Locator strings, you can use this locator strings depending on your use.


Full Video : 

Tuesday, 26 August 2014

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

It is very easy to configure selenium tool for asp.net website or project.

We can configure selenium tool and it's DLL into Visual Studio by creating new 'website' or 'project' or in Existing 'website' or 'project'.

In previous article you can see the article of how to download selenium webdriver tool.

Here are some steps to configure selenium webdriver tool :

STEP 1 : Open Visual Studio like VS2010, VS2012 or VS2013
STEP 2 : Go to File menu and click on 'New Web Stite' Menu, Now it will open dialog box in that dialog box select 'Empty Web Site' template and give your website name in below text box. After that click on 'OK'. Now your website is created.

Friday, 22 August 2014

Selenium Tool : Download selenium Webdriver for ASP.NET C#

Selenium is an excellent tool for automate series of use actions. It is also very useful for  testing. Here we are providing series of learning selenium tool.

Download selenium is the first stage to learn selenium.

STEP 1 : Go to selenium HQ URL, URL is 'http://www.seleniumhq.org/download/'.

STEP 2 : After that, scroll down page and find the 'Download' link in order to download zip file. You can see the Programming Language wise download link. Click on download link of C# row. You can see this in below image. After that, you can see download dialog box and save that in you local folder.

Wednesday, 2 July 2014

.Net Tips : Remove leading and trailing white spaces from string using Regex with C#.Net and VB.Net example

It is very easy to remove string's leading and trailing white spaces using Regex.

 The Regex is "^\s+|\s+$".

Here is example of this.

In this example we are taking on string which has leading and trailing white spaces. We can remove this spaces using Regex.

C#. Net Example :
string strData = "            This string contains leading and trailing white spaces             ";
strData = Regex.Replace(strData, @"^\s+|\s+$", "");
Response.Write(strData);

VB.Net Examples :
Dim strData As String = "            This string contains leading and trailing white spaces             "
strData = Regex.Replace(strData, "^\s+|\s+$", "")
Response.Write(strData)

  
Click here for other post regarding Remove only leading white spaces from string using Regex with C#.Net and VB.Net example


Click here for other post regarding Remove only trailing white spaces from string using Regex with C#.Net and VB.Net example


Wednesday, 25 June 2014

.Net Tips : Remove only trailing white spaces from string using Regex with C#.Net and VB.Net example

It is very easy to remove string's trailing white space.

We can achieve using Regex. The Regex is "[ \t]+$".

Here is example of this.

In this example we are taking on string which has trailing white space. We can remove this spaces using Regex.

C#. Net Example :
string strData = "This string contains trailing white spaces             ";
strData = Regex.Replace(strData, "[ \t]+$", "");
Response.Write(strData);

VB.Net Examples :
Dim strData As String = "This string contains trailing white spaces             "
strData = Regex.Replace(strData, "[ \t]+$", "")
Response.Write(strData)


Click here for other post regarding Remove only leading white spaces from string using Regex with C#.Net and VB.Net example

Click here for other post regarding Remove leading and trailing white spaces from string using Regex with C#.Net and VB.Net example.  


Wednesday, 18 June 2014

.Net Tips : Remove only leading white spaces from string using Regex with C#.Net and VB.Net example

It is very easy to remove string's leading white space.

We can achieve using Regex. The Regex is "^[ \t]+".

Here is example of this.
In this example we are taking on string which has leading white space. We can remove this spaces using Regex.

C#. Net Example :
string strData = "   This string contains leading white spaces";
strData=Regex.Replace(strData, "^[ \t]+", "");
Response.Write(strData);

VB.Net Examples :
Dim strData As String = "   This string contains leading white spaces"
strData = Regex.Replace(strData, "^[ \t]+", "")
Response.Write(strData)


Click here for other post regarding Remove only trailing white spaces from string using Regex with C#.Net and VB.Net example

Click here for other post regarding Remove leading and trailing white spaces from string using Regex with C#.Net and VB.Net example.