仅当我们使用超过3个关键字进行搜索时才会加载这些值。
depart = driver.find_element_by_xpath("//a[contains(@class, 'select2-choice select2-default')]")
depart.click()
depart.select_by_value('Delhi Indira Gandhi Intl (DEL)')
您可以尝试以下代码:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(driver, 10)
#...
fromPlace = "Delhi Indira Gandhi"
#If will not enter text to FROM field, uncomment click code below
#driver.find_elements_by_css_selector('#s2id_location_from a').click()
driver.find_element_by_id('s2id_autogen12').send_keys(fromPlace)
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='select2-result-label' and contains(.,'"+ fromPlace +"')]"))).click()