Reputation: 4062
I have a method to check if the drop down field has the selected value.
The value selected in the drop down in the GUI is "PAF".
I am using first_selected_option from the Select class which should check the selected value from the drop down field.
I use an If Then Else to check if the value from the drop down matches the expected value of "PAF"
I am getting False instead of True.
Here is my 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 my TestCase class the call to the method:
self.assertTrue(mappings.is_dropdown_selected_from_advanced_cleaning_output_tab("PAF"))
In the GUI PAF is selected in the drop down. Why is it returning false? What is wrong with my code?
I think I am not getting the string value correctly into the variable selected_dropdown_option I tried (str(selected_dropdown_option)) Is this not the correct way to get the string value?
Thanks, Riaz
Upvotes: 1
Views: 1680
Reputation: 373
I haven`t tested this, but try this. It looks like you try to cast your webelement to a string, you should get the 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
Upvotes: 0