Locating elements in Selenium - Selenium Tutorials Online

Selenium has become the widely preferred test automation tool for testing web based applications. In software testing the most important and difficult task is to locate elements. When you want to complete the test promptly and perfectly, you need to locate the right element within a short span of time. Selenium is highly user friendly and it offers different types of locators which can be used to make the process of locating elements in Selenium easier and swifter.

Different Types of Locators – Locating elements in Selenium

As mentioned earlier selenium has different types of locators and the user has the right to use the most suitable one depending on the nature of element and also the nature of the project.

Locating Elements by ID

ID of each element will be unique and it is very easy to locate the element by ID if you know the ID.

Finding Elements by Name

This is another easy method to locate an element. Usually the names will be easier to remember and hence most of the Selenium experts prefer this locator.

Finding Elements by Link Text

This locator can be used only when the element you care searching is a link text. It will work even with partial link texts. This is applicable only to the hyperlink texts.

Finding Elements by Class Name

When you are searching for an element which has a class and if you know the class name, this will be the better choice for finding elements within a short span of time.

Finding Elements by Tag Name

You may arrive at a situation on occasions where the element you are searching for does not have ID, Name, Link Text or Class. In such occasions this locator will come for your help. However, this is the least popular locator among all locators in Selenium and is used only when no other options are available.

Finding Elements by XPath

When all other locators fail, this can be used to find an element. XPath is just XML and  it uses HTML DOM structure to find elements.

When you execute a test, you need to locate an element to perform something on it. Hence, locating element is an important task in test automation. A professional tester should be capable enough to select the right type of selector to make the process easier and swifter. Even in Selenium tutorials, importance is given to the portion discussing about locators in selenium.

Leave a Reply

Your email address will not be published. Required fields are marked *