[英]What are the ways of selecting element from auto-suggestion dropdown?
自动建议来了。 html元素如下:
<div angucomplete-alt id="ac-{{row.RowId}}" placeholder="Search materials..." maxlength="50" pause="100" selected-object="selectedCon" ng-click="selectedConRow(row)" local-data="materialsConsumables" search-fields="MaterialName" title-field="MaterialName" initial-value="row.materialSelected" minlength="1" input-class="autocomplete" match-class="highlight"></div>
将所有建议收集到一个“列表”中,并在与所需字符串匹配时选择一个元素。
码::
String producttoSelect = "0007950137 - BSS 500ML GLASS -CDN";
WebElement ConProduct1 = objDriver.findElement(By.xpath("//*[@class=\"con_Material ng-isolate-scope\"]/div/input"));
ConProduct1.sendKeys("0007950137 - BSS 500ML GLASS -CDN");
try {
Thread.sleep(5000);
} catch (Exception e) {
}
List<WebElement> productList = objDriver.findElements(By.xpath("//*[@class=\"con_Material ng-isolate-scope\"]/div/div"));
for (WebElement optionP : productList) {
System.out.println(optionP.getText());
if (optionP.getText().equals(producttoSelect)) {
System.out.println("Trying to select Product: " + optionP.getText());
optionP.click();
break;
}
}
尝试使用Explicit wait而不是thread.sleep,直到填充列表:
By aaa = By.xpath("//*[@class=\"con_Material ng-isolate-scope\"]/div/div");
List<WebElement> suggestList =
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(aaa));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.