I'm using selenium in python, and I have a dropdown that I'm trying to select from. Essentially, I just want to iterate through all the options, like so:
select first option
submit page
\\ do stuff
select second option
submit page
\\ do stuff
select third option
submit page
\\ do stuff
etc...
I know it's possible to do this if you know what each of the option values are (you just create a list of those values), but is there a way of just iterating through all the options when you don't know what the option values are?
Thanks!
You can get list of all the options using select.options. Than you can select options using index.
select = Select(driver.find_element_by_id("dropDown"))
options = select.options
for index in range(0, len(options) - 1):
select.select_by_index(index)
# do stuff
You can simply iterate through all options:
select = Select(driver.find_element_by_id("someId"))
for opt in select.options:
# for example
print(opt.text)
opt.click()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With