My code uses selenium to go select options from a drop down menu. I have a code that looks just like this:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.website.com")
browser.find_element_by_xpath("//select[@id='idname']/option[text()='option1']").click()
This works just fine. But there are many options in the drop down menu and I wish to loop over all items in the drop down menu. I prepared the following code to loop over the options:
options = ["option1", "option2"]
for opts in options:
browser.find_element_by_xpath("//select[@id='idname']/option[text()=opts]").click()
This does not work. Any suggestion on how to get such a loop to work? Something I do not understand about loops in python?
Thank you.
This should work for you. The code will
Like so: