When I select "selectedText" text in "fieldLabel" field

Focuses a form field and selects a specific substring of its current value. The step reads the field's value, finds the first occurrence of the given text, and applies a selection range covering exactly that occurrence. If the text is not present in the field, the step fails with a clear message naming both the text and the field. The field is located with an accessibility-first lookup chain: label text, then placeholder, then a textbox with a matching accessible name, and finally a name attribute or element id.

This is the most readable way to select text when you know what should be selected but not where it sits, for example selecting one word out of a sentence before replacing or formatting it. The match is case sensitive and only the first occurrence is selected. The selection is applied through the field's native selection range, so it works on text inputs and textareas.

Accepted phrasings

When I select "<text>" text in "<field>" field
When we select "<text>" text in "<field>" field
When select "<text>" text in "<field>" field

Examples

When I select "title name" text in "Title" field
When I select "hello" text in "Body" field
When I select "admin" text in "Username" field
When I select "summary" text in "Message" field

In a real scenario

Scenario: Select a word inside the notes field by its text
  Given I am on "/articles/draft/edit"
  When I fill in "hello world" for "Notes"
  And I move focus to "Notes" field
  And I select "world" text in "Notes" field
  When I fill in "hello portal" for "Notes"
  And I press "Save"
  Then I should see "hello portal"

Related steps

Back to Selectors Steps