Selenium with C# : How to do Google search with selenium C# ?

Steps:


  • Create a webDriver instance with any browser.
  • Navigate to google search page
  • Find the search text box and enter search text and click enter.


Sample program: 

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

namespace DemoAutomation
{
    class SampleProgram
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();
            Thread.Sleep(5000);
            //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.google.co.in/?gfe_rd=cr&ei=cr7tWMbCCOSK8QfB5JjgBA");
            IWebElement wb = driver.FindElement(By.Id("lst-ib"));
            wb.SendKeys("Sachin");
            wb.SendKeys(Keys.Enter);

        }
    }
}

1 comment:

Copyright © 2017 QALEARNINGGUIDE.COM || ALL RIGHTS RESERVED