How to solve ElementNotVisibleError: element not visible in protractor

How to solve ElementNotVisibleError: element not visible in protractor

var spinner = element(by.css('.glyphicon.glyphicon-ok.green:not(.ng-hide)'));
expect(spinner.isDisplayed()).toBeTruthy();
spinner.click();

当我执行这个时总是收到一个错误

ElementNotVisibleError: element not visible

我要select这个元素

<span class="glyphicon glyphicon-ok green" data-ng-show="Choice.IsCorrect"/>

而不是 select 其他元素作为

<span class="glyphicon glyphicon-ok green ng-hide" data-ng-show="Choice.IsCorrect"/>

正确的做法如下

var popUp = ($('[data-ng-show="Choice.IsCorrect"].glyphicon.glyphicon-ok.green:not(.ng-hide)'));
popUp.click();

所以这将始终 return 可见元素并且可以点击它。

谢谢大家的关注