Skip to content
CodeKruPro

Locate an element by its name attribute

Automation taskEasyAsked in: Accenture, Capgemini, TCS, Wipro

Form fields often have a name attribute, because the form sends that name to the server with the value. Interviewers ask you to list the locator strategies and say when you use each; name is the usual second choice after id. Here you find a read-only field by its name and print its value and tag name.

Find Element by Name

Video walkthrough

Watch on YouTube

Find Element by Name

The By.name() locator finds an element using its name HTML attribute.

On the Text Fields page, the readonly field (#4) has:

  • Name: uneditable
  • Value: Codekru
  • It is readonly

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Find the element by name uneditable
  3. Print its value and tag name

Expected output:

Value: Codekru
Tag: input