自动提示来了。 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;
}
}
答案 0 :(得分:0)
而不是thread.sleep,尝试使用Explicit wait直到填充列表:
By aaa = By.xpath("//*[@class=\"con_Material ng-isolate-scope\"]/div/div");
List<WebElement> suggestList =
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(aaa));