×
☰ See All Chapters

How to locate element by name locator in selenium

To extract the user input of GUI elements from server’s side, many languages like Java expects the name attribute to be attached to the form elements. Most of the time we need to automate the UI forms and UI form elements will be added with name attribute. Name locator in Selenium can be used by these name attributes. One problem while using name locator is, name attribute can be used for many elements with same value. In this case locator selects the first element with that name on the page. Below is the syntax and example for name locator:

Syntax:

name=value of name attribute

Example:

name=lastname

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

Let us test name locator from our test page Test Page

selenium-name-locator-0
 
selenium-name-locator-1
 

All Chapters
Author