Skip to content
CodeKruPro

Read attribute values of an input

Automation taskEasyAsked in: Accenture, Capgemini

A frequent question: "What is the difference between reading the text and reading an attribute?" Text is what the user sees; an attribute is a name and value in the HTML tag, such as type="email". Read the value, name and type of a field.

Get Attribute Value with getAttribute()

Get Attribute Value

getAttribute() reads any HTML attribute value. Common attributes: value, name, id, class, placeholder, type, href.

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Find the pre-filled field (ID: preFilledTextField)
  3. Print its value, name, and type attributes

Expected output:

Value: Codekru
Name: preFilledTextField
Type: text
Read full tutorial on Codekru