Reputation:
I got such problem:
I need to configure all options on the page with Selenium. I need to use Select class from Python Selenium. Here is example:
select = (Select(driver.find_elements_by_css_selector('select'))
select.select_by_index(2)
and I got nothing instead! I think that Select works only with one element. And what to do, when i need to configure ALL select in this way? Thank you!
Upvotes: 0
Views: 247
Reputation: 160
You can create a generator for that; so you can iterate while wrapping the elements:
selects = driver.find_elements_by_css_selector('select')
def wrapped_selects():
for element in selects:
yield Select(element)
or you can wrap them all:
selects = map(Select, driver.find_elements_by_css_selector('select'))
Upvotes: 1