hubcap select

Select a dropdown option by its value attribute.

When to use

Use select to choose an option from a native <select> dropdown by matching the <option> value attribute. Use click on custom dropdown elements that are not native <select> elements.

Usage

hubcap select <selector> <value>

Arguments

ArgumentTypeRequiredDescription
selectorstringYesCSS selector of the <select> element
valuestringYesValue attribute of the <option> to select

Flags

None.

Output

FieldTypeDescription
selectedbooleanWhether the selection succeeded
selectorstringThe selector of the dropdown
valuestringThe value that was selected
{"selected":true,"selector":"#country","value":"us"}

Errors

ConditionExit codeStderr
Element not found1error: JS exception: <message>
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Select a country from a dropdown:

hubcap select '#country' 'us'

Select a size option:

hubcap select '[name="size"]' 'large'

Select an option then verify the value was set:

hubcap select '#country' 'us' && hubcap value '#country'

See also

  • fill - Fill a text input
  • value - Get the current value of an input
  • check - Check a checkbox
  • forms - Get all form elements on the page