Select
Type: select
Use select to choose one or more options from a native HTML <select> dropdown.
Parameters
selector
string
The selector that defines the <select> element the browser should choose an option from.
timeout
integer
The maximum amount of time the browser should wait for the element defined by the selector to appear. Default: 5000 (5s)
See universal parameters.
Values
The values array tells Gaffa which option or options to select. Each item identifies one option using either its HTML value attribute or its visible label.
value
string
Matches an option using its HTML value attribute.
label
string
Matches an option by its visible text. Only used when value is absent or empty.
Each item must include at least one non-empty
valueorlabel. If both are provided,valueis used andlabelis ignored.For a single-select field, provide one item in
values. For a multi-select field, provide one item for each option you want selected. All items are applied to the same<select>element.If an item doesn't match an option, it is skipped. The action succeeds if at least one item matches and fails if none match.
Usage
Select an option by value
The following selects the option with value 108 from a dropdown.
Select an option by label
The following selects the option whose visible text is Laws .
Select using both value and label
If an item includes both value and label, value is used and label is ignored. The following selects the option with the value 108 ("Passed/agreed to in House"), not the option labelled Laws, even though both are supplied.
Select multiple options in a multi-select field
The following selects two options, 118 and 117, in the same multi-select dropdown.
FAQs
When do I use the select action?
Use it to choose an option, or several options, in an HTML <select> dropdown or multi-select field. For text fields, use type, and for checkboxes, radio buttons, or custom dropdowns built without a real <select>, use click.
How do I select an option from a dropdown?
Add a select action with a selector for the <select> element and a values array containing either the option's value or its label.
How do I select multiple options in a multi-select field?
Submit multiple items in values, one per option, all pointed at the same selector. Each one applies to the same field, so you end up with several options selected in one dropdown rather than one option per field.
What's the difference between selecting by value and by label?
value matches the option's underlying value attribute, label matches its visible text. If an item includes both, value is used and label is ignored, label only comes into play when value is missing or empty.
Why did my select action fail?
Either the selector didn't match a <select> element in time, or none of the items in values matched an option on the page. Non-matching items are skipped rather than failing individually; the whole action only fails if nothing in values matched anything.
How do I know if a select worked?
Add a capture_screenshot after the select action. Browsers don't update the selected attribute in the raw HTML when an option is chosen programmatically, so capture_dom or capture_element will still look like nothing changed, even when the select succeeded.
Can I use select on a custom dropdown that isn't a real <select> element?
No. Many modern sites replace the native control with a JavaScript widget, often an input[role="combobox"] with its own list of options. select only works against a genuine <select> element; for a custom widget, use click to open it and click each option instead.
Last updated