Setting up
WebDriver
1.Create a
new project from Console App
2.Install
Selenium NuGet packages
3.Download
the driver for particular browser.For Firefox browser we don’t need to install
the driver.Here we installed Chrome driver using below link.It actually runs
directly.
https://chromedriver.storage.googleapis.com/index.html?path=2.40/
4.Add OpenQA
namespace under Selenium and we need to import namespace for browser also.
5.Now we
write a small code which open up our browser and go to google.com.
6.Output of the code
7. Finding
Elements
For finding
elements we have to right click on the element we want and click on inspect
option.
8.Then we
will see that element must has an Id or class or we can also use Xpath to select
the element.
9.Now we
extends the previous code which will search for “Selenium”
10.Then it
will select the image option and will click the first image of selenium.
11.Extended
code
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace SeleniumDemo
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Url = "https://www.google.com/ncr";
var searchbox = driver.FindElement(By.Id("lst-ib"));
searchbox.SendKeys("Selenium");
searchbox.SendKeys(Keys.Enter);
var imageOption = driver.FindElement(By.ClassName("qs"));
imageOption.Click();
var image = driver.FindElement(By.Id("i48MSmX01sE18M:"));
image.Click();
}
}
}
12.Output
of the code
Comments
Post a Comment