I'm trying to select (if present) a month of the year in a dropdown list, where (month) can be any string from 'January' to 'December' (these are also the elements on the dropdown list)
But not every month is necessarily on the list.
Select(driver.find_element_by_id("selectMonth")).select_by_visible_text("%s" % (month))
"selectMonth" is the id of the list, and the visible text is named according to the month. I have created a loop where I select each month from January to December, but I'm having problems when the month isn't on the list (NoSuchElementException).
How do I check if the month is on the dropdown list before trying to select it?
There's some good information about NoSuchElementException in this other post (Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome), but I couldn't use it to solve my problem. It's similar, but not the same.