using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
namespace SeleniumWebDriverAutomation
{
[TestClass]
public class GoogleSearch
{
// webdriver dirver definition
public IWebDriver driver = new ChromeDriver();
[TestMethod]
public void navigateToGoogleWebSite()
{
// Go to google web site
driver.Navigate().GoToUrl("https://www.google.lk/");
// Maximize the web browser
driver.Manage().Window.Maximize();
//call searchSomething method
searchSomething("Selenium");
}
public void searchSomething(string searchString)
{
//find the google text searchbox by uisng html id and key in passed search string
driver.FindElement(By.Id("lst-ib")).SendKeys(searchString);
//find the google search button by uisng html name and click on it
driver.FindElement(By.Name("btnG")).Click();
}
}
}
Demo run of above code
Comments
Post a Comment