问题
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