When I select "option" from "select list" by attribute

Selects an option from a dropdown (<select>) element that you target by attribute rather than by its visible label. In webship-js 2.0.x this is handled by the same select "..." from "..." step: when the second argument starts with # or . it is used as a CSS selector for the id or class, and a bare single word is matched against the select element's name attribute or its id. The separate by attribute suffix from earlier releases is no longer needed.

The option itself is matched by visible text first, then by its value attribute as a fallback. If several elements match the attribute lookup, the first one on the page is used. This step replaces the current selection; to add to a multi-select without clearing existing choices, use additionally select.

Accepted phrasings

When I select "option" from "#select-id"
When I select "option" from ".select-class"
When we select "option" from "select-name"
And I select "option" from "select-name"

Examples

When I select "Mercedes" from "#cars"
When I select "Mercedes" from ".cars"
When we select "Saab" from "cars"
And I select "English" from "language"

In a real scenario

Scenario: Switch the text format of the body field while editing content
  Given I am logged in as a content editor
   When I go to "/articles/add"
    And wait
    And I fill in "Format switch test" for "Title"
    And I select "full_html" from "body[0][format]"
    And wait
   Then the option "Full HTML" should be selected within the select element "[name='body[0][format]']"

Related steps

Back to Form Steps