Selenium Automated Testing – Preliminary Problem (Part 1)

Tram Ho

Hi readers, after a long time with busy projects as well as my laziness, I did not practice automation testing regularly. I also forgot a lot of basic knowledge. After a challenging campaign I came back, today I will learn about Automation test again. This article is for first-time contacts as well as those who want to follow the road of automated testing. The main purpose is to cultivate myself the basic knowledge to serve my work and future career. My post may be similar or similar to some articles on the same topic on some other forums. However, I will write with the language closest to, most understandable, hope that you will help in some part of the process of self-learning automation test by yourself.

The first is the definition

What is automated testing?

According to wikipedia

Automated testing is the use of special software (separate from the software being tested) to perform test scenarios and compare actual results with expected results. Automated testing can automate a number of repetitive but necessary tasks in a formalized testing process, or as additional tests that are difficult to perform manually. Automated testing is important for release and ongoing testing.

What is selenium

SELENIUM is a free, open source automated testing framework, used to authenticate web applications on different browsers and platforms. You can use many programming languages ​​like java, C #, Python … to create Selenium test scripts. Testing is done using the Selenium tool commonly known as Selenium Testing

There are many types of automated testing using Selenium, in this article I will only talk about Selenium WebDriver because it’s simple and it’s enough for me.

Prepare the environment

There are a lot of pages about setting up environment now, so I won’t go back. You can refer to this page:


Once the environment is complete, let’s try some basic code

Problem 1 : Check if the title of the web page is correct with the expected results. Try it on

Run the above class and the result will be as follows:

In addition to checking the website title, we also have to check many elements inside the website. So how to get each element in our website to the math problem 2.

Problem 2 : Try searching for a song on Youtube

There are 2 issues that need clarification

  • How to know which textbox to search?
  • How to click the search button to find results
  1. There are many ways to search for an element in a web page
VariationDescriptionFor example
By.classNameSearch for an element based on the value of the “class” attributefindElement (By.className (“someClassName”))
By.cssSelectorSearch for the element based on the CSS Selector tool below the driverfindElement (By.cssSelector (“input # email”))
By.idSearch for elements based on the value of the “id” attributefindElement ( (“someId”))
By.linkTextSearch for exact elements based on the displayed linkTextfindElement (By.linkText (“REGISTRATION”))
By.nameSearch for elements based on the value of the attribute “male”findElement ( (“someName”))
By.partialLinkTextLocate the components that contain the partialLinkTextfindElement (By.partialLinkText (“REG”))
By.tagNameLocate the components based on the tag namefindElement (By.tagName (“div”))
By.xpathLocate components based on the XPath path/ html [1] / body [1] / table [1]
  1. Do the maths
  • To get the element that is the search box textbox, move the mouse on the test part to get => F12 (or right-click and select Inspect element). From here, let’s get the characteristics of that element. You can install the Chropath tool in the extension for Crhrome to get the element more accurately.
  • For example, get the correct element via the Chropath tool

To solve this problem, I will use XPath to get the element

The results obtained when the Run class is as follows:

In the following article, I will write about more practical and difficult problems. Please read the References

Share the news now

Source : Viblo