我正在测试表单,它具有类别字段,它是基于输入的下拉菜单。用.send_keys('text')添加一些文本后,它会显示一个类别列表。看看它的HTML:
<input type="text" aria-required="true" id="categories" maxlength="64" value="" autocomplete="off" class="input__69f5f__1POmY" placeholder="Pizza (Be specific)">
我正在这样做是为了查找并提交输入文本:
categories = browser.find_element_by_id('categories').send_keys('Software Development')
之后,它显示一个类似列表:
[请有人可以帮助我,如何单击下拉菜单中的选项?
我正在使用Firefox Webdriver。
谢谢。
这不是一个很好的解决方案,但我会进行如下编码以从下拉列表中选择项目。
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