How to click on the first auto suggestion or first searched value on https://www.airdna.co/

大憨熊 提交于 2019-11-29 17:09:13

As per your question to get the value of the first suggestion within the website https://www.airdna.co/ once you send the search related character sequence you need to induce WebDriverWait for the desired element to be visible/clickable and you can use the following solution:

  • Code Block:

    driver.get("https://www.airdna.co/")
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"input.ui-autocomplete-input"))).send_keys("la roch")
    print(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"ul.ui-menu.ui-widget.ui-widget-content.ui-autocomplete.ui-front>li>div"))).get_attribute("innerHTML"))
    
  • Console Output:

    La Rochelle, FR
    
  • Browser Snapshot:


Incase you want to click on the first auto suggestion you can use:

  • Code Block:

    driver.get("https://www.airdna.co/")
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"input.ui-autocomplete-input"))).send_keys("la roch")
    print(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"ul.ui-menu.ui-widget.ui-widget-content.ui-autocomplete.ui-front>li>div"))).get_attribute("innerHTML"))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"ul.ui-menu.ui-widget.ui-widget-content.ui-autocomplete.ui-front>li>div"))).click()
    
  • Console Output:

    La Rochelle, FR
    
  • Browser Snapshot:

Replace click event with action class:

from selenium.webdriver.common.action_chains import ActionChains

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