【问题标题】:Selecting value from dropdown not working with angularJS application从下拉列表中选择值不适用于 angularJS 应用程序
【发布时间】:2017-01-12 03:23:30
【问题描述】:
<div id="Select2_msdd" class="dd ddcommon form-control form-control-gender form-control-input styled-select-dd-lrg ng-isolate-scope ng-pristine ng-valid ng-invalid ng-dirty borderRadius" tabindex="0" style="z-index: 1; background-color: rgb(255, 255, 255);">
<div class="ddTitle borderRadiusTp">
<span class="divider"></span>
<span id="Select2_arrow" class="ddArrow arrowoff"></span>

我正在尝试单击箭头并从下拉列表中选择一个选项。我遵循的方法是,首先我将点击'//span[@id='Select2_arrow']',然后点击下拉菜单中的一个选项。

这适用于 chrome 和 IE。但是当谈到 Mozilla 时,单击箭头可以工作,但要从下拉列表中选择一个选项。单击该选项有效,此步骤已通过。但实际上选项没有被选中。

选项的xpath是//*[@class='enabled _msddli_']//*[@class="ddlabel" and text()="General Question"]

<li class="enabled _msddli_">
<span class="ddlabel" style="background-color: transparent;">General Question</span>

下拉类中的选项的 HTML。 注意:我不想使用 javascriptexecutors。

【问题讨论】:

  • HTML 代码中是否存在任何&lt;input type="checkbox"&gt; 元素?
  • 请尝试在 dd 中的选项选择可能有帮助之前进行预期的等待\
  • @Andersson 感谢您的回复。没有
  • @rajNishKuMar : 在该步骤之前已经调用了一个 waitUntil

标签: angularjs selenium selenium-webdriver


【解决方案1】:

您可以在此处更改选项的 xpath。

//span[text()='一般问题']

您还可以使用不同的定位器,例如 css 选择器。 请通过遍历选项列表找到访问选项的代码:

String str="General Question";

Select list= new Select(driver.findElement(By.id("mention the drop down locator you are using")));
       List<WebElement> listSize = list.getOptions();
       int iListSize = listSize.size();
      // System.out.println(iListSize);

       // Setting up the loop to select all the options
            for(int j =0; j < iListSize ; j++){
            // Storing the value of the option  
            String sValue = list.getOptions().get(j).getText();

            // Selecting all the elements one by one
         if (sValue.equalsIgnoreCase(str){
            list.selectByVisibleText(sValue);
            Thread.sleep(50);
            }
         }

虽然遍历下拉菜单需要一些时间,但你可以试一试!!希望这会有所帮助!

【讨论】:

  • 1- OP 没有要求对所有选项进行迭代 2- Select 仅适用于 &lt;select&gt; 标签 3- 问题出在点击中,而不是在定位元素上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多