×
☰ See All Chapters

How to locate element by class name locator in selenium

Class Name locator helps in locating element defined through the class attribute. If in case class is used only with one element, it can be used for class name locator. But multiple elements on the web page can have same class; in such case selenium always locates the first matching element. Below is the syntax and example for class name locator:

Syntax:

className=value of class attribute

Example:

className=datePicker

Note: There should be no space/emptyspce before and after = (equals)

Let us test class name locator from our test page Test Page

selenium-classname-locator-0
 
selenium-classname-locator-1
 

All Chapters
Author