What is Selenium? Selenium - C # Making Boots with

Ayberk Cakar
Innovile
Published in
4 min readSep 4, 2020

Hello, what is selenium in this article, What areas it is used in, how its terminology is How to use selenium with C#, How to make a simple bot, how we add our data to our database, I’ll address the answers to questions such as how to automate our bot. I hope it will be useful for you 😊.

What Is Selenium? Where is it used?

If we define selenium, we can call it a “Browser Automation” tool, so some testing steps of websites , it is a tool that allows you to create and operate automatically through your web browser as you specify.

You can write Selenium in a variety of programming languages; Python,Java,C#,Ruby,JavaScript,Kotlin etc.

Let’s Understand Selenium Logic

In order to perform test operations on Selenium websites; can enter data in the necessary inputs, receive data on the website, and click buttons. In other words, it can perform any action that the client can do.

As we can test with this method , we can also get the data we want from websites.

Required Installations for Selenium

For the necessary installations, we enter NuGet Packages via Visual Studio.

We download Selenium.WebDriver.

I installed Selenium.Chrome.WebDriver, you can install whatever you want; Firefox.WebDriver, InternetExplorer.WebDriver…

Selenium Terminology

With the ChromeOptions and ChromeDriverService methods, we make the settings we want for the ChromeDriver, then we set these assign as parameters to the ChromeDriver.

Note: If we want to run our Web Driver invisibly, that is, if we want our transactions to be performed without opening our web browser; We must specify “- -headless” in our settings.

  • Window.Maximize() → Allows us to maximize the window size.
  • Navigate().GoToUrl(“https://…”) → It allows us to go to the website we want.
  • FindElement() → It allows us to search the HTML of the website.

For search;

  • By.Xpath(“/html/body/form/div/div[2]/input”) → We can use XPath, which we get through Html.
  • By.Name(“btnK”) →We can use Name, which we get through Html.
  • By.ClassName(“RNmpXc”) → We can use Class, which we get through Html.
  • By.Id(“gb_71”) → We can use Id, which we get through Html.
  • By.CssSelector(“form>div>span.break-words>div#RNmpXc”) → We can write by following the CssSelector of the structure we want through Html.
  • Note: For ClassName “. “, We use “ # “ for Id.
  • .SendKeys(“…”) → Provides us to enter data in inputs.
  • .Click() → Allows us to click on clickable structures.
  • .Submit() → Allows us to click on submit structures.

ReadOnlyCollection<IWebElement> datas = WebDriver.FindElements(By.ClassName("break-word"));

  • If we explain through the example, With this structure, it collects all data on Html, whose Class name is “break-word”, into “datas”.
  • With the sample code structure, we can download the Scroll of our window. We can move the structure up and down, right and left with ScrollBy().
  • Webdriver.Quit() →We are finalizing the webdriver.

Application: Getting Weather Information via Google

Saving Data in Oracle Database

I used Oracle Database as Database in my project, and I wanted to share it with you. You can use any database you want.

  1. STEP: We install the Oracle.ManangedDataAccess Package

2. STEP: We fill in database information to Oracle connection

3. STEP: We Write The Required Query To Add Data To The Database

Automating Our Bot

We may want to run the bot at certain times (daily, weekly, hourly, etc.). There is a simple solution for this. With the Windows Task Scheduler tool on our computer ,If we want it to work both on our computer or server, we can do this on a Windows Server.

  1. STEP: We Create New Task

2. STEP: Creating Trigger Settings

3. STEP: We Create the Desired Action to Run

Good Works 😊

--

--