Non-Select Drop-down list selection using Selenium Python


I’m trying to print the options and select "Manhattan" from the "city" dropdown search box on this website: . But every time I run it, the program end without printing anything. In addition, could anyone show me how to type part of a city’s name (like "Manha") and then select from the dropdown list?

My code is shown below. Could anyone help?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import By
from import WebDriverWait
from import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from import Select
import time

PATH = "/usr/local/bin/chromedriver"
driver = webdriver.Chrome(PATH)
    city = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'input-74')))

    # city.send_keys("o")
    # city.send_keys(Keys.RETURN)

    city_selection = Select(city)
    # print the number of option

    # print all options
    for option in city_selection.options:

    # select by index
    # select by value
    # city_selection.select_by_value()



The desired element isn’t within any tag, but they are within <div> tag.


So you won’t be able to use Select() class.


To print the option texts you can use List Comprehension and you can use the following locator strategies:

  • Code block:

    driver.execute("get", {'url': ''})
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accept all']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[text()='City']//following-sibling::input[1]"))).click()
    print([my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='v-menu__content theme--dark menuable__content__active v-autocomplete__content']//div[@role='option']//div[@class='v-list-item__title']")))])
  • Note : You have to add the following imports :

    from import WebDriverWait
    from import By
    from import expected_conditions as EC
  • Console output:

    ['Los Angeles', 'San Francisco', 'Manhattan', 'Queens', 'Fresno', 'Brooklyn', 'Oakland', 'Staten Island', 'Bakersfield', 'Chicago', 'Cleveland', 'Santa Clara', 'Rutherford', 'Kansas City', 'New Orleans', 'Nashville', 'Bronx', 'Detroit', 'Las Vegas']

To select Manhattan:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='v-menu__content theme--dark menuable__content__active v-autocomplete__content']//div[@role='option']//div[@class='v-list-item__title' and text()='Manhattan']"))).click()

Answered By – undetected Selenium

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published