Create a new Unit Test project
Get Selenium.Support and Selenium.WebDriver from NuGet - my packages.json looks like this:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Selenium.Support" version="2.48.2" targetFramework="net452" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net452" />
</packages>
A very simple implementation looks like this (be sure to populate the strings)
[TestMethod]
public void TestMethod1()
{
const string directoryContainingChromeDriver = @"C:\tools\chromedriver_win32";
const string url = "YOUR URL GOES HERE";
const string searchBoxSelector = "YOUR SELECTOR GOES HERE for example input.search";
IWebDriver webDriver = new ChromeDriver(directoryContainingChromeDriver);
webDriver.Navigate().GoToUrl(url);
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
IWebElement searchBox = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.CssSelector(searchBoxSelector));
});
searchBox.SendKeys("ChromeDriver");
var logs = webDriver.Manage().Logs.GetLog("browser");
// just for the purposes of this demo
Thread.Sleep(5000);
webDriver.Close();
}
References