填写部分文本后如何单击自动完成功能? [英] How to click on an autocomplete after filling partial text?
问题描述
我正在测试一个表单,它具有一个类别字段,它是一个基于输入的下拉菜单.用.send_keys('text')添加一些文本后,它会显示一个类别列表.看看它的HTML:
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 at its HTML:
<input type="text" aria-required="true" id="categories" maxlength="64" value="" autocomplete="off" class="input__69f5f__1POmY" placeholder="Pizza (Be specific)">
我这样做是为了查找并提交输入文本:
I am doing this to find and submit input text:
categories = browser.find_element_by_id('categories').send_keys('Software Development')
在那之后,它显示如下列表:
after that, it shows a list like:
请有人帮助我,如何单击下拉菜单中的选项?
Please someone can help me, how can I click on an option in the drop-down menu?
我正在使用Firefox Webdriver.
I am using the Firefox webdriver.
谢谢.
推荐答案
要单击文本为 Professional Services> Software Development 的选项,您必须诱使 WebDriverWait element_to_be_clickable()
,则您可以使用以下任一定位器策略:
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:
这篇关于填写部分文本后如何单击自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!