using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace TopNugetPackages
{
class SeleniumMainDriver : ITopNugetPackages
{
private IWebDriver driver = null;
public SeleniumMainDriver()
{
// actual finds file chromedriver.exe that matches version of browser installed
driver = new ChromeDriver(@"C:\Users\sp\Downloads");
}
private void GoogleSearch()
{
driver.Navigate().GoToUrl("http://google.com");
IWebElement element = driver.FindElement(By.Id("gbqfq"));
element.SendKeys("selenium webdriver");
// Get the search results panel that contains the link for each result.
IWebElement resultsPanel = driver.FindElement(By.Id("search"));
// Get all the links only contained within the search result panel.
ReadOnlyCollection<IWebElement> searchResults = resultsPanel.FindElements(By.XPath(".//a"));
// Print the text for every link in the search results.
foreach (IWebElement result in searchResults)
{
Console.WriteLine(result.Text);
}
}
public void SimpleTest()
{
driver.Navigate().GoToUrl("https://www.computerhope.com/htmcolor.htm");
Thread.Sleep(2000);
IWebElement element = driver.FindElement(By.ClassName("sbar"));
element.SendKeys("blue");
Thread.Sleep(1000);
element.SendKeys(Keys.Enter);
}
// Demonstration on how to use Selenium Web Driver to perform testing on Web functionalities
public void DoIt()
{
SimpleTest();
}
}
}