getting current <select> value from drop-down menu with Python Selenium
user_defined_type_dropdown_element
is the <select>
tag, that is why you are getting all the options when printing it. If you want the selected option use Select
class and first_selected_option
# initialize Select objectselect = Select(user_defined_type_dropdown_element)# to print the textprint select.first_selected_option.text# to print the valueprint select.first_selected_option.get_attribute("value")
Check that under Select, there are 4 option's, so u have to select each option if u want to get each option's value.
Use this in ur Xpath for first option value
//table[@id="data_configuration_edit_data_object_tab_details_tb_fields"]/tbody/tr[1]//td[3]//select//option[1]
For Python-Selenium Dropdown code, the below code can be used to initially get the selected value form the drop down and accordingly change the value by using selenium dropdown operations like Select_by_value or Select_by_indexI the below code we are first collecting the current value of the drop down in "dropdown_value" and later we can put some condition to verify it
----------get_value = driver.find_element_by_id("id")dropdown_value = get_value.get_attribute("value")----------