Selenium Locators

The Selenium Locators are commands, that tells IDE which IDE elements it needs to operate on. The identification of the correct GUI element is a prerequisite to creating the automation script. using locators, we can match the element pages and interact with them.

Selenium Locators

ID element():

Each element has a unique ID.  We can easily find the elements using ID locator. According to W3c, ID’s are unique on the page and makes it more reliable. And this is the fastest and safest elementor.

id= id of the element


Name locator():

It is used to identify the elements on the web page. Moreover, locating elements using Name locator is the same as locating using Name locator. But these are not unique on the page. And if there are multiple elements with the same name locator, then the first element on the page is selected. And the test fails, if another element with the same name locator is present on the web page.

name = name of the element

 syn :


Class name locator():

This gives the element that matches the value specified with the class  attribute “class”

 syn :

findElement(By.className(“class name”))

Tag name locator():

This is used to find elements matching with a specific tag name. Moreover, it is helpful when we extract the content within a tag.

 syn :

findElement(By.tagName(” Tag Name”))

Link Text locator():

This locator works on hyperlinks. And if there are multiple elements with the same link text then the first one will be selected.

 syn :


 Partial Link text locators():

There are some situations, where we need a link to the certain portion of text. In such cases,  we use partial link text locators.

 syn :


CSS selector Locator():

This the best way to locate the elements on the web page. Many testers believe,  CSS makes the test execution faster. Moreover, testers added, this selector makes the test execution faster. And they added, it is the best way to locate the elements on the page.   Selenium supports the following CSS selectors.

Tag and ID :


Tag and Class:


Tag and Attribute:


Tag, Class, and Attribute:


Xpath locator:

Xpath locator can easily navigate the XML documents. Its purpose is to select individual elements, attributes, and some other parts for XML document for specific processing. Moreover, this XPath produces reliable locators. But when compared to CSS selector, this has slow performance.



Testing a page :

To start testing the webpage , we need to open the webpage ad provide a URL to navigate to the page. Run the folling code in the Eclipse IDE  to naviagte to the facebook login page.

package seleniumWebDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WebDriverClass
public static void main(String[] args)
System.setProperty(“webdriver.gecko.driver”, “files/geckodriver.exe”);
WebDriver driver = new FirefoxDriver();

Also check the importance of Cross Browser testing

to our newsletter

Drop Us A Query

Trending Courses
  • Pega testing training
    PEGA Testing Training
  • Today application testing is the deciding factor to launch the application into the market. And people do not launch the application unless it goes true.

  • blockchain course
    Blockchain Online Course
  • Today many people were enthusiastic, to know the exact details of things happening around him. This can get the proper knowledge on Blockchain.

  • ethical hacking course
    Ethical Hacking Certification Course
  • Zeal to learn ethical hacking is common among college students and IT professionals. Because everybody wants to secure their system from cyber attacks.

  • python training
    Python Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Training
    Tableau Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • what is pega
    PEGA Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).

100% Secure Payments. All major credit & debit cards accepted.