Selenium Python Check if dropdown is selected with the expected value. I am getting False -


i have method check if drop down field has selected value. value selected in drop down in gui "paf".
using first_selected_option select class should check selected value drop down field. use if else check if value drop down matches expected value of "paf" getting false instead of true.

here selenium webdriver python code snippet:

def is_dropdown_selected_from_advanced_cleaning_output_tab(self, field):     selected_dropdown_option = select(self.get_element(*mainpagelocators.mappings_paf_output_dropdown)).first_selected_option     print (str(selected_dropdown_option))     if (str(selected_dropdown_option)) == field:         return true     else:         return false 

from testcase class call method:

self.asserttrue(mappings.is_dropdown_selected_from_advanced_cleaning_output_tab("paf")) 

in gui paf selected in drop down. why returning false? wrong code?

i think not getting string value correctly variable selected_dropdown_option tried (str(selected_dropdown_option)) not correct way string value?

thanks, riaz

i haven`t tested this, try this. looks try cast webelement string, should text. e.g : selected_dropdown_option.text

def is_dropdown_selected_from_advanced_cleaning_output_tab(self, field):           selected_dropdown_option = select(self.get_element(*mainpagelocators.mappings_paf_output_dropdown))     selected_dropdown_option.select_by_visible_text(field)     selected_text = selected_dropdown_option.text     if(selected_text == field):         return true     else:         return false 

Comments