Get the value of an input element
| || ||Keyword to identify the field. |
The associated label, aria-label, placeholder, adjacent text, and current value can be used to identify a field.
CSS and XPATH selectors can also be used, but is not recommended as it makes the tests harder to keep up to date.
Returns: The value of the input element
# Using field label
You can use the field's
name, and nearby text to identify the field.
I.fill("Search", "Hello") I.type(" from the other side") var searchTerm = I.getValue("Search") // This will be "Hello from the other side"
This command gets the value of the input field identified as "Search" and sets it to the variable
# Using field CSS / XPATH
You can also use CSS and XPATH to identify the field.
var email = I.getValue(".input-email")
This command gets the value of the input field with the CSS class
input-email and sets it to the variable
Use hard selectors like CSS / XPATH sparingly because it makes your tests fragile and harder to read and maintain.