How to click on an autocomplete after filling partial text?

后端 未结 2 842
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 18:45

I am testing a form, it has a categories field, it\'s an input-based drop-down menu. After add some text with .send_keys(\'text\') it shows a list of categories. Take a look

2条回答
  •  孤街浪徒
    2021-01-15 19:30

    To click on the option with text as Professional Services > Software Development you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

    • Code Block:

      from selenium import webdriver
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      
      driver.get("https://biz.yelp.com/signup_business/new")
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='categories']"))).send_keys("Software Development")
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='categories']//following::div[1]/ul/li"))).click()
      
    • Browser Snapshot:

提交回复
热议问题