Selects one or more options in a <select> element. The element is identified using one of the provided selector strategies. Options can be selected by value, label, or index. Example: selectOption(selector: "#country", values: [{ value: "US" }]) Returns true if the options were successfully selected.

Definition

selectOption(
  selector: String
  text: String
  role: String
  label: String
  placeholder: String
  altText: String
  title: String
  testId: String
  filter: ElementFilterOptions
  values: [SelectValueOptions]!
  options: SelectOptionOptions
): Boolean!

Arguments

selector: String

The CSS selector for the element. Example: "#username" for <input id="username" />.

text: String

Finds an element by its text content. Example: "Login" for <button>Login</button>.

role: String

Finds an element by its ARIA role. Example: "button" for <div role="button">Submit</div>.

label: String

Finds an element by its ARIA label. Example: "Search button" for <button aria-label="Search button"><svg/></button>.

placeholder: String

Finds an element by its placeholder text. Example: "Enter your email" for <input placeholder="Enter your email" />.

altText: String

Finds an element by its image alt text. Example: "Company logo" for <img alt="Company logo" src="..." />.

title: String

Finds an element by its title attribute. Example: "Close dialog" for <span title="Close dialog">X</span>.

testId: String

Finds an element by its data-testid attribute. Example: "submit-button" for <button data-testid="submit-button">Go</button>.

filter: ElementFilterOptions

Advanced filtering options for the element.

values: [SelectValueOptions]!

An array of option values to select. Options can be specified by value, label, or index.

options: SelectOptionOptions

Options for the select action, such as forcing the action or setting a timeout.

Returns

Boolean!

The Boolean scalar type represents true or false.