Book Image

Selenium Essentials

By : Prashanth Sams
Book Image

Selenium Essentials

By: Prashanth Sams

Overview of this book

Table of Contents (12 chapters)

Locating WebElements

Element-locating functions are the building blocks of Selenium tests. These methods handle Ajax calls using timeouts and wait conditions to search and locate elements within a web page. There is no fixed strategy that you can follow to locate an element; it depends on the user ideology and their comfort level in locating the web elements.

An element can be located using any kind of locator type. Selenium WebDriver uses locators to interact with elements present in a web page. The following is the list of locator types used in Selenium WebDriver to locate web elements:



  • By.xpath

  • By.cssSelector

  • By.className

  • By.linkText

  • By.tagName

  • By.partialLinkText

The following is the syntax to use locatorType:


The following is an example for locatorType:


Prioritize the locator type in this order: id > name > css > xpath. The cssSelector locator type is a good pick to work with Ajax calls....