In order to output my already selected option I coded:
Select(driver.find_elements(By.XPATH,'path_to_select/select/option'))
selected_option = select.first_selected_option
print(selected_option)
Error Message:
raise UnexpectedTagNameException( selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on elements, not on
CodePudding user response:
Because you are selecting a list of elements. So you can use driver.find_element()
instead of driver.find_elements() to select a single element.
select = Select(driver.find_element(By.XPATH,'path_to_select/select/option'))
selected_option = select.first_selected_option
print(selected_option)
CodePudding user response:
driver.find_elements
returns list of WebElements
should be driver.find_element
. Note the s
in find_element