Reputation: 103
I'm trying to select a value from a dropdown list on the web, but the HTML doesn't have any Select or Option tags. The values of the list are in a table and not embedded in the code. I do have the ability to enter text into this box so I figured an easy solution would be just to use .sendkeys (on the webpage if the entered text matches a dropdown option it works), but I guess Python won't let you do that to a combobox because I just get an element is not visible error. I found the below link with a full breakdown of how to interact with dropdown lists, but the "Without Select Option" section only has examples for Java and Ruby.
Below is the inspected code of the dropdown box.
What are my options?
<span class="custom-combobox">
<input title="" class="custom-combobox-input ui-widget ui-widget-content ui-corner-left ui-autocomplete-input" autocomplete="off">
<a tabindex="-1" class="ui-button ui-widget ui-button-icon-only custom-anchor custom-combobox-toggle ui-corner-right" role="button">
<span class="ui-button-icon ui-icon ui-icon-triangle-1-s">
</span><span class="ui-button-icon-space"> </span></a></span>
<span class="ui-button-icon-space"> </span>
Upvotes: 0
Views: 2549
Reputation: 582
Just found a very simple solution for this annoying problem, Been looking around for days just to solve it, Selecting dropdowns without Select class
# Find your dropdown element by the following, finds the element in the dropdown named BRA
Dropdown_Element = driver.find_element(By.XPATH, "//*[text()='BRA']").click()
# Store the ActionChains class inside the actions variable
actions = ActionChains(driver)
# Click on the element using the click(on_element=)
actions.click(on_element=Dropdown_Element)
time.sleep(2)
actions.perform()
Upvotes: 2