How to use selenium in C#. environment setup
I share how to crawl the web using selenium in C#.
1. Required programs
-. Installation of IDE and Visual Studio required for writing C# programs
2. Install Nuget
-. If you look at Visual Studio's tools menu, there is a Nuget manager.
Nuget admin
-. Afterwards, if you search for Selenium in the Nuget search box, the list is displayed as shown below.
Of these, if you install Selenium.WebDriver, Selenium.Support, Selenium.WebDriver.ChromeDriver, and DotnetSeleniumExtras.WaitHelpers, the necessary packages for Nuget will be installed.
3. Create a C# project
Now create a C# project.
If you write a using statement as shown below, you are ready to use selenium.
using OpenQA. Selenium;
using OpenQA. Selenium. Chrome;
using OpenQA.Selenium.Support.UI;
4. Write a C# Selenium function
Here's a simple way to write a function:
When the test function is called, the Naver page is opened, and it waits for up to 5 seconds to be searched.
The hardest part of coding is thread synchronization, but it can be handled simply like this.
void test() {
using (IWebDriver cDriver = new ChromeDriver())
{
// access blog URL
cDriver.Url = "https://www.naver.com";
cDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
}
}
I plan to post about selenium from time to time.
I would like to share it in several languages such as C# and python.
Comments
Post a Comment