Reputation: 4062
I have a weird problem. I have a drop down element and I would like to select the value "No". My Selenium Python code will not select the value "No".
I tried to click the element to see if the click works and that the element can be interacted with, visible etc.
The click works, the drop down element opens.
My Selenium Python code is:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
def select_use_for_matching_dropdown(self, value):
# Params value: The value for the Matching drop down Yes or No
try:
select = Select(WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.ID, 'data_configuration_edit_data_object_tab_details_lb_use_for_match'))))
select.select_by_visible_text(str("No"))
except NoSuchElementException, e:
print "Element not found "
print e
self.save_screenshot("select_use_for_matching_dropdown")
The HTML is:
<select id="data_configuration_edit_data_object_tab_details_lb_use_for_match" class="gwt-ListBox marginright">
<option value="yes">yes</option>
<option value="no">no</option>
<option value="exclude data categories">exclude data categories</option>
</select>
Is there any other way I can try to select the value "No"
I have also tried
select = Select(self.driver.find_element_by_id('data_configuration_edit_data_object_tab_details_lb_use_for_match'))
select.select_by_visible_text('No')
Thanks, Riaz
Upvotes: 0
Views: 1642
Reputation: 1440
I hope this code will help you.
from selenium.webdriver.support.ui import Select
select= Select(driver.find_element_by_id('id_of_element'))
Selecting 'no' option from given dropdown
select.select_by_index(1)
select.select_by_value('no')
select.select_by_visible_text('no')
Upvotes: 0
Reputation: 17553
Try any one from below:-
select.select_by_visible_text('no')
OR
select.select_by_value('no')
Hope it will help you :)
Upvotes: 1
Reputation: 1342
Not sure if uppercase matters in the Python driver but your actual values are lowercase 'no' so you might want to try
select.select_by_visible_text('no')
Upvotes: 1