Skip to content

Selects

Interactions with select tag.

Reading the element

Getting the right element class for the xpath

my_select = web.element('//*[id="mySelect"]')
type(my_select)
Output
fastrpa.core.elements.SelectElement

Try to get a SelectElement

my_select = web.select('//*[id="mySelect"]')
type(my_select)
Output
fastrpa.core.elements.SelectElement

Reference

Get all options from the select

my_select.options
Output
{'1': 'Option 1',
 '2': 'Option 2'}

Get just the options values

my_select.options_values
Output
['1', '2']

Get just the options labels

my_select.options_labels
Output
['Option 1', 'Option 2']

Select the option by label

my_select.select('Option 1')

Select the option by value

my_select.select(value='1')

Get the current value from the select

my_select.current
Output
('1', 'Option 1')

Check if an option exists, by label and value

'Option 3' in my_select
Output
False

Check if an option exists, just by label

my_select.has_option('Option 3')
Output
False

Check if an option exists, just by value

my_select.has_option(value='3')
Output
False

Extra needed!

To use this method, you need to install the debug extras, as shown here, with the command pip install "fastrpa[debug]".

my_select.print()
Output
[@id="mySelect"]
├── [1] Option 1
├── [2] Option 2
├── [3] Option 3
└── [4] Option 4