繁体   English   中英

从自动建议下拉列表中选择元素的方式是什么?

[英]What are the ways of selecting element from auto-suggestion dropdown?

  1. 使用sendkeys输入字段。
  2. 自动建议来了。 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>

  3. 将所有建议收集到一个“列表”中,并在与所需字符串匹配时选择一个元素。

  4. 选择值并将其填充到输入字段中
  5. 填写所有其他必填字段
  6. 点击“提交”。 但是显示该输入字段具有值的错误。 (PS:手动运行,应用程序本身没有问题。)

码::

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.

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