Sunday 16 March 2014

How to enter the data in web edit box with selenium webdriver in C#.Net?

Entering the values in the text boxes is very simple.
First you have to find the textbox or editbox using any of the element identification method and then You can use SendKeys() method to enter a value in the text box.

Complete example in C#.Net is given below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using OpenQA.Selenium;

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System.Collections.ObjectModel;
namespace Abc
{
    class Program
    {
        static void Main(string[] args)
        {

           
IWebDriver driver=null;
try
{
driver = new ChromeDriver(@"F:\selenium\csharp");
driver.Url = "http://www.google.co.in";

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));

driver.Navigate();

//enter data in google search box

driver.FindElement(By.XPath("//*[@id='lst-ib']")).SendKeys("Selenium Book in C#");

            }

 catch(Exception e){
 Console.WriteLine("Exception ******"+e.ToString());
               
 }
           
            finally{
            Thread.Sleep(2000);
            driver.Quit();
            Console.ReadLine();
            }

           
        }
    }
}




What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

1 comment:

  1. amazing!!!! thanks very much...not getting webdriver with c# at many places..

    ReplyDelete

Buy Best Selenium Books

Contributors