This step clicks an element located by one of its HTML attributes rather than by visible text. You provide the attribute value to match, and optionally the attribute name (such as id, class, name, placeholder, or a data-* attribute). When no attribute name is given, the step delegates to buildSelector, which infers the most appropriate selector from the value - for example, a value starting with # is treated as an id, while a plain string is checked against common attributes in turn.
This variant is the right choice when a button has no readable text (icon-only buttons, image buttons) or when the visible label is ambiguous and an attribute provides a more stable target. The selector resolves to the first matching element. Unlike the text-based press step, there is no automatic error hint on failure, so the selector must be correct and the element must be present in the DOM.
Accepted phrasings
When I press "btn-submit" by attr
When I press "btn-submit" by attribute
When we press "save-draft" by attr
And I press "Your full name" by "placeholder" attribute
And I press "Your full name" by its "placeholder" attribute
And I press "save-name" by "data-selector" attr
Examples
When I press "btn-pressid" by attr
When I press "btn-pressid" by attribute
And I press "Your full name" by "placeholder" attribute
And I press "save-name" by "data-selector" attr
In a real scenario
Scenario: Submit the newsletter form using the button data attribute
Given I am on "/newsletter"
When I fill in "alice@example.org" for "Email"
And I press "subscribe-btn" by "data-selector" attr
Then I should see "Thank you for subscribing"
Related steps
- Press button by visible text - press a button using its exact visible label
- Click link or button by attribute - click any link or button using an attribute selector
- Click link or button by text - click any link or button by its visible text
- Attach file to input - set a file on a file input element