-1

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

2 Answers2

1

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)
Md. Fazlul Hoque
  • 15,806
  • 5
  • 12
  • 32
  • it shows: **selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on –  Sep 07 '22 at 12:27
  • 2
    You can follow answers from here how to select dropdown correctly: https://stackoverflow.com/questions/7867537/how-to-select-a-drop-down-menu-value-with-selenium-using-python – Md. Fazlul Hoque Sep 07 '22 at 12:32
0

driver.find_elements returns list of WebElements

should be driver.find_element. Note the s in find_element

Akzy
  • 1,817
  • 1
  • 7
  • 19