当用selenium python测试phptravels网站的下拉时我遇到了这个问题。我无法从下拉列表中选择值

问题描述 投票:1回答:1

仅当我们使用超过3个关键字进行搜索时才会加载这些值。

enter image description here请帮我找一个解决方案 - 我的代码如下......

depart = driver.find_element_by_xpath("//a[contains(@class, 'select2-choice select2-default')]")
depart.click()
depart.select_by_value('Delhi Indira Gandhi Intl (DEL)')
python python-3.x selenium selenium-webdriver selenium-chromedriver
1个回答
0
投票

您可以尝试以下代码:

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()
© www.soinside.com 2019 - 2024. All rights reserved.