Tuesday, 30 September 2014

Selenium C# : Insert text in website textbox with selenium C# webdirver

Click Here to Download InsertTextInTextBox.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.


Using selenium C# webdriver API we are able to insert text in website textbox element automatically in web browser. This article is very useful for automate website testing.

To enter text in textbox we need locator string of that particular textbox. To get locator string you need to your FireFox Element Locator Add-on.

Here is example for insert text in textbox automatically:
In this example first we open website 'www.google.com'. After that, we locate search textbox using locator add-on. Now in C# code we create object of FireFoxDriver Class.

We are using 'FindElement' method of 'FireFoxDriver' Class object, in this object we are finding element using 'XPath'. We are using 'OpenQA.Selenium.By.XPath' method. After finding element we are using 'SendKeys' method to insert text in textbox.

In 'SendKeys' method's parameter pass your desire text or string. This method exist in 'OpenQA.Selenium.IWebDriver.ISearchContext.FindElement' class.

Selenium C# 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)
    {

        OpenQA.Selenium.IWebDriver objFF = new OpenQA.Selenium.Firefox.FirefoxDriver();
        objFF.Navigate();
        objFF.Url = "http://www.google.com";
        objFF.FindElement(OpenQA.Selenium.By.XPath("//input[@id='gbqfq']")).SendKeys("ASP.NET");
                
    }
}

[Image : Open 'www.google.com' and enter text] :
 
Selenium C# : Insert text in website textbox with selenium C# webdirver
(To view original size image , click on image)

Prerequiest to learn this article :

You need to learn these previous articles before learning this article.

Selenium Tool : Configure selenium tool for asp.net C# website or project in Visual Studio.
Selenium Tool : Download and Install WebDriver Element Locator Add-on.

Full Video : 



9 comments:

  1. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

    ReplyDelete
    Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. The blog you have shared is very much helpful to know more about the selenium. Thanks for your information about the selenium.
    selenium testing training
    selenium testing course
    selenium training classes
    selenium classes
    selenium training course

    ReplyDelete
  3. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.



    selenium training in chennai


    java training in chennai

    ReplyDelete
  4. Nice post,and good information Thanks for sharing further check it once at
    .NET Online Training Hyderabad

    ReplyDelete
  5. The article seems to be more informative. This is more helpful for our selenium training in chennai Thanks for sharing

    ReplyDelete
  6. Hi, I am getting error while execute Sendkeys in selenium after finding element using XPath. Below are the code statements,
    IWebElement objElement = ((IWebDriver)clsRunConfiguration.objBrowser).FindElement(By.XPath(sDOMXPath));
    objElement.SendKeys(sValueToBeSet); //Error is "Invalid Argument, text must be string\n"
    Need urgent help to resolve this issue.

    Regards,
    Nikunj

    ReplyDelete