All IT Courses 50% Off
Selenium Tutorials

Locators in Selenium IDE

In Selenium IDE, locators are used to identify elements on a web page so that you can interact with them during test execution. Locators are essential for automating web tests as they allow Selenium IDE to find and manipulate elements like buttons, text fields, links, etc. Locators tell Selenium IDE which GUI elements as needed to use on. The identification of correct GUI elements can be important whenever we build automation script. But wherever the accurate identification of GUI elements will be more difficult. Selenium will provide a number of Locators to locate GUI elements. There are different types of CSS locators in Selenium

There are many commands that will not need the locator. The most of them need the locators element in selenium webDriver.

Locating ID:

The id attribute uniquely identifies an element on the page. You can use it as a locator in Selenium IDE by prefixing it with id=.

Example: id=submit_button

All IT Courses 50% Off

The most common way of locating elements since ID’s are to be unique for each element.

Format: Id=Id of the element

For example:  Facebook will test app as it has changed its login page demo page is used for testing that is http://demo.iitworkforce.com/test/facebook.html when we inspect the “email or phone” text box by using Firebug and has  of its ID. The “ID” email

How to use Locators in Selenium IDE

Launch the selenium IDE and enter the “id=email” in the target box. Click the find button and also see that “email or phone” text box becomes highlighted with an yellow and bordered with green, meaning- Selenium  IDE will be able to locate the element.

How to use Locators in Selenium IDE

Locating By Name using the filters

Filters will be used when the multiple elements will have the same name. Filters are the additional attributes that is used with the same name.

The name attribute is used to give the element a name. You can use it as a locator in Selenium IDE by prefixing it with name=.

Example: name=username

Format : name=name_of_the _element filter=value_of_filter

For example when we log into any app using the username and password, it will take to the main page. They find the value of the attribute by using the options for radio buttons and also other buttons and also can be used as a filter. When we are going to access the way radio button box first. Click the first line on the editor. In the command box enter “name=username” and the value =oneway portion of our filter. We may click the find button and see that selenium IDE can be used to highlight the radio button with the green meaning that are able to access the element successfully using the VALUE attribute. When we press X key in the keyboard to run the click command. That is the only way radio button became selected.

How to use Locators in Selenium IDE

As it is used fire Locators are command that tells Selenium IDE which GUI elements as its requires to operate on. As the identification of correct GUI elements will be a prerequisite whenever we build an automation script. But wherever the accurate identification of GUI elements will be more difficult. Selenium will provide a number of Locators to locate GUI elements. There are different types of CSS locators in Selenium.

Locating by CSS selector:

CSS selector in the selenium has string patterns to identify  element that is depend on a combination of the HTML tag, id,class and also attributes.Locating by CSS Selectors in Selenium  is more complicated than the previous method but it is the common locating strategy of advanced selenium users because it is an access as elements that have no ID or name.

Many CSS selectors of the selenium have formats may focus on the most common on

  • Tag
  • Tag and also class
  • Tag and also attribute
  • tag and class an attribute
  • inner text

Whenever we will be using this strategy we have to prefix the target box with=”CSS”.

CSS selectors are patterns used to select elements in an HTML document based on their attributes. You can use CSS selectors as locators in Selenium IDE.

Example: input#username

Class Name: 

You can use it as a locator in Selenium IDE by prefixing it with class=.

Example: class=btn-primary

XPath: 

XPath is a powerful query language used to navigate through elements and attributes in an XML or HTML document. You can use XPath expressions as locators in Selenium IDE.

Example: //input[@id=’username’]

Link Text: 

You can locate links on a web page by using the visible text of the link. You can use it as a locator in Selenium IDE by prefixing it with link=.

Example: link=Login

Partial Link Text: 

Similar to link text, but you can use a partial match of the link text. You can use it as a locator in Selenium IDE by prefixing it with partialLink=.

Example: partialLink=Forgot Password

Tag Name: 

You can locate elements by their HTML tag name. You can use it as a locator in Selenium IDE by prefixing it with tag=.

Example: tag=button

When recording or manually creating test scripts in Selenium IDE, you can use these locators to interact with elements on the web page and perform actions like clicking, typing text, verifying content, etc.

Questions

  1. What are locators?What are uses of locators in Selenium IDE?
  2. How locators are used as CSS selectors?give examples
Facebook Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button