Using Selenium with C#
First of all, we will talk about how to install the selenium library and then we will try to access a site in its simplest form.
Right click on the default project and select Manage NuGet Packages.
Then, when you type “selenium” in the search section, the relevant packages will come.
We refer to the 1st and 3rd (Selenium.WebDriver and Selenium.WebDriver.ChromeDriver) NuGets.
We click the Install button.
Our packages are defined.
Now we add our codes.
IWebDriver driver = new ChromeDriver();
We call Driver.
driver.Navigate().GoToUrl(URL);
With this code snippet, we are redirecting to the page we want.
@Test
public void test1() {
WebElement searchText =driver.findElement(By.name("q"));
searchText.sendKeys("KoçFinans");
driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
}
Our scenario would be like this:
go to google page
Type KoçFinans in the Search field.
Click Enter.
Wait 2 seconds.
Close the browser.
Our next step is to examine our plugin, which is necessary for our tests to run in the browser. First of all, we need to learn the chrome version, we can learn it as follows.
When we choose about Google Chrome, the chrome version appears as follows.
It will automatically update itself.
When we run the project; The steps will take place the way we want.
Project codes are in the attached link.