Angularjs 获取错误“;失败:元素当前不可见,因此可能无法与";

Angularjs 获取错误“;失败:元素当前不可见,因此可能无法与";,angularjs,jasmine,protractor,Angularjs,Jasmine,Protractor,在尝试此操作时,单击元素作为: element.all(by.repeater("condition in filterCtrl.conditions")).get(1).click(); 我得到的错误如下: Failed: Element is not currently visible and so may not be interacted with". 我怎样才能克服这一点 我的CSS如下 <div class="_md-select-menu-container _md-a

在尝试此操作时,单击元素作为:

element.all(by.repeater("condition in filterCtrl.conditions")).get(1).click();
我得到的错误如下:

Failed: Element is not currently visible and so may not be interacted with". 
我怎样才能克服这一点

我的CSS如下

<div class="_md-select-menu-container _md-active _md-clickable" aria-hidden="false" id="select_container_198" style="display: block; left: 764px; top: 181px; min-width: 234.547px;"><md-select-menu class="ng-scope _md-overflow" style="transform-origin: 101.273px 72px 0px;"><md-content>
<!-- ngRepeat: condition in filterCtrl.conditions --><md-option ng-repeat="condition in filterCtrl.conditions" value="CONTAINS" tabindex="0" class="ng-scope md-ink-ripple" aria-selected="false" role="option" id="select_option_257"><div class="_md-text ng-binding">Contains</div></md-option><!-- end ngRepeat: condition in filterCtrl.conditions -->option ng-repeat="condition in filterCtrl.conditions" value="ENDS_WITH" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_261"><div class="_md-text ng-binding">Ends with</div></md-option><!-- end ngRepeat: condition in filterCtrl.conditions -->
</md-content></md-select-menu></div>"

Containsoption ng repeat=“过滤器中的条件trl.conditions”value=“以”tabindex=“0”class=“ng scope md ink ripple”role=“option”aria selected=“false”id=“select\u option\u 261”结束
"

错误告诉您元素当前不可见,这就是它无法执行单击的原因。不确定您的应用程序是如何设置的,是否有角度,等等。但我建议尝试两种方法:

1) 如果该元素确实已加载,请尝试将其滚动到视图中

var scrollIntoView = function () {
    arguments[0].scrollIntoView();
}
browser.executeScript(scrollIntoView, yourwebelement);


2) 确保元素实际存在并显示在页面上。如果您将代码更改为
expect
语句并添加
.isPresent()
.isDisplayed()
-返回真值吗?根据您的错误,我猜
isPresent()
返回真值,但
isDisplayed()
返回false。如果是这种情况,请尝试添加隐式等待函数,等待元素加载后再尝试单击它。

这是因为在单击元素之前打开了弹出窗口。通过单击URL来处理此问题,以便关闭弹出窗口,从而使量角器可以与元素交互。

T我想这个错误是很明显的。为什么你需要“点击”这个元素?如果你想用这个元素做点什么,为什么不直接在你的函数中做呢?