How to click on an autocomplete after filling partial text?

后端 未结 2 845
伪装坚强ぢ
伪装坚强ぢ 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:14

    this is not an elegant solution but I'd go about coding something like below to select the item from the dropdown.

    import time
    from selenium.webdriver import Chrome
    
    driver = Chrome()
    driver.get('https://biz.yelp.com/signup_business/new')
    categories_input = driver.find_element_by_id('categories')
    categories_input.send_keys('Professional')
    
    time.sleep(5) # replace with webdrive wait
    categories_container = categories_input.find_element_by_xpath('..')
    categories = categories_container.find_elements_by_css_selector('li[class*="suggestion-list-item"]')
    
    for category in categories:
        if category.text == 'Professional Services':
            category.click()
            break
    

提交回复
热议问题