Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (47.6k points)

What are the different types of locators in Selenium?

1 Answer

0 votes
by (106k points)

The Selenium locators allow its users to access HTML elements from a web page like text boxes, labels, hyperlinks, radio buttons, checkboxes, etc. To check types of locators as you know while writing scripts for automation testing we inserting some input data in the application and verify the results. If you want to learn Selenium you can take up the following Selenium Training Course.

There are many types of Locators which are as follows:-

  • ID

  • Name

  • Link Text

  • Partial Link Text

  • Tag Name

  • Class Name

  • CSS Selector

  • XPath

  • ID locator in Selenium:-

The ID is a well-known locator in Selenium WebDriver, ID gives a unique identity to the element. It helps while writing scripts where multiple choices are existing.

  • Name locator in Selenium:-

Same as ID, the Name locator can be useful if the ID locator is missing but make sure that every time name attribute cannot be unique.

  • Link Text locator in Selenium:-

Talking about Link Text locator so it is used to click on any anchor text. Make sure that anchor text (Link Text) should not be duplicated.

  • Partial Link Text locator in Selenium:-

Partial Link Text Locator is the same as Link Text Locator only difference is we can write “Partial Link Text” instead of full link text.

  • TagName locator in Selenium:-

It is mostly used to Check Boxes and Dropdown list.

  • ClassName locator in Selenium:-

The ClassName locator can be used if the class name is available. If you are using the rest of the locators there is a chance of duplication.

  • CSS Selector in Selenium:-

CSS Selector is really very fast and handy for automation testing. CSS Selector gives multiple choices like:

    1. Tag and ID

    2. Tag and class

    3. Tag and attribute

    4. Tag, class, and attribute

    5. Inner text

  • Xpath locator in selenium:-

XPath locator is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes or some other part of an XML document for a specific processing

    1. Type of Xpath locator:

    2. Native Xpath

    3. Relative Xpath

These are the types of locators that help to make automation scripts easy. I hope you will use these types of locators in your work. If you want to explore these more then you must read the following Selenium Tutorial. Here is the video tutorial through which I came to know all about these things.

.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...