【问题标题】:Selenium Python - select from autosuggest dropdownSelenium Python - 从自动建议下拉列表中选择
【发布时间】:2017-07-10 18:00:18
【问题描述】:

当我在下一页的“输入公司”字段中使用值为“ada”的 sendkey 时,我试图从自动建议列表中选择下拉列表的第一个值。 http://www.moneycontrol.com/stocks/histstock.php

inputElement = driver.find_element_by_xpath("""//*[@id="mycomp"]""")
inputElement.send_keys('ada')   
driver.find_element_by_xpath("""//*[@id="suggest"]/ul/li[1]""")

这似乎不起作用。

请帮忙。

问候,

babsdoc

【问题讨论】:

    标签: python web-scraping selenium-chromedriver


    【解决方案1】:

    尝试等到DOM中出现所需选项:

    from selenium.webdriver.support.ui import WebDriverWait as wait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    driver.find_element_by_id("mycomp").send_keys('ada')
    wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="suggest"]/ul/li[1]'))).click()
    

    【讨论】:

    • 这就像安德森的魅力。感谢您的帮助,衷心感谢。
    猜你喜欢
    • 2020-11-27
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2012-09-22
    相关资源
    最近更新 更多