繁体   English   中英

如何在Selenium中选择aria-autocomplete输入字段?

[英]How to select aria-autocomplete input field in Selenium?

我遇到了这个自动完成输入文本字段。 HTML是:

 <div id="customfield_11930-single-select" class="aui-ss ajax-ss long-field" data-query="35mm Capture - 2.7.1"> <input id="customfield_11930-field" class="text aui-ss-field ajs-dirty-warning-exempt" type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" aria-busy="false"> <div class="ajs-layer-placeholder"> <span class="icon aui-ss-icon drop-menu noloading"> <span>More</span> </span> </div> <select id="customfield_11930" class="single-select long-field hidden js-sprint-picker aui-ss-select" data-saved-state="" data-saved-id="" data-container-class="long-field" name="customfield_11930" style="display: none;" multiple="multiple"> <option value="" selected="selected"> </option> </select> 

我对这个HTML的理解是:

input(customfield_11930-field)是用户输入的文本字段

div(ajs-layer-placeholder)存储所有自动完成/建议

span()是用户点击弹出自动完成/建议列表的地方

select(customfield_11930)是显示自动完成/建议的位置

所以,如果我使用代码:

myDriver.findElement(By.id("customfield_11930-field")).sendKeys("35mm Capture - 2.7.1");

截图将显示:

在此输入图像描述

现在如何选择自动完成/建议列表中的第一项?

“Select”元素现在是否填充了所有建议列表项?

我做的事情如下:

new Select(myDriver.findElement(By.id("customfield_11930"))).selectByVisibleText("35mm Capture - 2.7.1");

但它不起作用。

实际上我对这种类型的自动完成选择菜单如何工作感到很困惑,它似乎比普通的下拉列表复杂得多。

任何一个解释? 谢谢,

在文本输入后,有一个带有id suggestions的新动态字段,您可以单击css选择器的第一个建议为#suggestions > li:nth-child(1) 你可以看到下面的代码:

蟒蛇:

driver.find_element_by_css_selector("#customfield_11930-field").clear()
driver.find_element_by_css_selector("#customfield_11930-field").send_keys("35mm Capture - 2.7.1")
driver.find_element_by_css_selector("#suggestions > li:nth-child(1)").click()

Java的:

driver.findElement(By.cssSelector("#customfield_11930-field")).clear();
driver.findElement(By.cssSelector("#customfield_11930-field")).sendKeys("35mm Capture - 2.7.1");
driver.findElement(By.cssSelector("#suggestions > li:nth-child(1)")).click();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM