Selenium Python - select from autosuggest dropdown

感情迁移 提交于 2019-12-12 04:07:36

问题


I'm trying to select the first value of the drop down from the autosuggested list when I use sendkey with a value of 'ada' into the "Enter Company" field on the following page. 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]""")

This doesn't seem to do the trick.

Please help.

Regards,

babsdoc


回答1:


Try to wait until required option appears in 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()


来源:https://stackoverflow.com/questions/45018802/selenium-python-select-from-autosuggest-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!