0

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

Riaz Ladhani
  • 3,946
  • 15
  • 70
  • 127
  • look if it helps you http://stackoverflow.com/questions/36471904/how-to-select-a-drop-down-menu-option-value-using-selenium-python also if you want java equivalent then i can give a sample code – Rajnish Kumar Apr 07 '16 at 10:03
  • Thanks for the link, have tried it. My other drop down elements work. Something strange with this one, it does not select the value. – Riaz Ladhani Apr 07 '16 at 10:09
  • 1
    i think the element which you want to select is loaded in the DOM (EC working) but when you select option no at that point of time position of option No is not fixed inside the DOM so one possible solution is before coming directly to dd with option no please do some other task it will allow no option to get its position inside the DOM and after that it will work like charm – Rajnish Kumar Apr 07 '16 at 10:20
  • Yes I have had to this with some of my other elements. Thanks for the tip – Riaz Ladhani Apr 07 '16 at 10:36
  • i am glad that tip helped you – Rajnish Kumar Apr 07 '16 at 10:38

3 Answers3

1

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')
the-noob
  • 1,322
  • 2
  • 14
  • 19
1

Try any one from below:-

select.select_by_visible_text('no')

OR

select.select_by_value('no')

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

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

  1. The select_by_index() method to select an option using the index attribute.

select.select_by_index(1)

  1. The select_by_value() method to select an option using the value attribute.

select.select_by_value('no')

  1. You can use match the text which is displayed in the drop down.

select.select_by_visible_text('no')

suba
  • 1,320
  • 15
  • 22