如何在md-option中执行量角器测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在md-option中执行量角器测试相关的知识,希望对你有一定的参考价值。

我有角度的代码

<md-input-container> 
  <label>Country </label>
    <md-select name="country" ng-model="country"required >
     <md-optgroup label="Select Country">
      <md-option ng-repeat="item in countryList"  ng-value="item" >
                 {{item.countryName}}
         </md-option>
       </md-optgroup> 
     </md-select> 
</md-input-container>

并且在下面使用了Protractor中的代码

 element(by.model("country")).click();
 browser.sleep(2000);
 element.all(by.repeater("item in countryList").row('1')).click();

我总是得到游戏错误

失败:元素不可见

在代码中元素(by.model(“country”))。click()工作正常,但没有在弹出窗口中选择md-option请帮忙。

答案

尝试下面的代码(你应该选择第一个元素。

 element(by.model("country")).click();
 browser.sleep(2000);
 element.all(by.repeater("item in countryList").get(1)).click();

如果仍然面临问题您可以尝试滚动直到该元素。

         element(by.model("country")).click();
         browser.sleep(2000);
         var elementToSelect = element.all(by.repeater("item in countryList").get(1));
         browser.executeScript('arguments[0].scrollIntoView(true)',elementToSelect.getWebElement());
         elementToSelect.click();

以上是关于如何在md-option中执行量角器测试的主要内容,如果未能解决你的问题,请参考以下文章