量角器UI Nav测试的麻烦定位Angular元素 [英] Trouble locating Angular element for Protractor UI Nav test

查看:52
本文介绍了量角器UI Nav测试的麻烦定位Angular元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在下拉列表中选择第三个选项.以下是有关该元素的一些详细信息:

I'm trying to select the third option in a dropdown list. Below are some details about the element:

外部HTML:

<md-option _ngcontent-c6="" role="option" ng-reflect-value="last90Days" tabindex="0" id="md-option-2" aria-selected="false" aria-disabled="false" class="mat-option"><!--bindings={
  "ng-reflect-ng-if": "false"
}--> Last 90 Days <!--bindings={
  "ng-reflect-ng-if": "true"
}--><div class="mat-option-ripple mat-ripple" md-ripple="" ng-reflect-trigger="[object HTMLElement]"> </div> </md-option>

CSS选择器:

#md-option-37 > div:nth-child(1)

抱歉,格式糟糕.如果有人对如何选择过去90天"下拉菜单有任何建议,那么我将不胜感激.

Sorry for the terrible formatting. If anyone has any suggestions about how to select the "Last 90 Days" dropdown item then I'd be very grateful.

推荐答案

基于我对您的信息的了解,以及对AngularJS md-select 的了解,您需要执行以下操作

Based on what I understand out of your info an the AngularJS md-select you need to do the following

// Open the md-select, use the correct selector, this is a demo
$('md-select').click();

// There is an animation, I don't know how long, you need to wait for the animation to be finished. 
// Quick and dirty is a browser.sleep(), but it's better to find a more stable way because if the animation will take longer in the future your test will break
browser.sleep(500);

// Click on you option, this can be done in several ways

// By index
$$('md-option').get(1).click();
// By text
element(by.cssContainingText('md-option', 'your text')).click();

// Wait for the menu to close, this is also an animation
browser.sleep(500);

对于 element(by.css('selector')); ,我始终使用

For element(by.css('selector')); I always use the shorthand notation, for the rest of the selectors see the docs of Protractor.

我建议使用更好的方法来等待动画完成.在这里,我使用了 browser.sleep(),但这不是未来的证明.您不希望您的脚本依赖睡眠.

I would advice to use a better way to wait for the animation to be done. Here I used a browser.sleep(), but it's not future proof. You don't want your script to rely on sleeps.

希望有帮助.

这篇关于量角器UI Nav测试的麻烦定位Angular元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆