【问题标题】:Getting the error "Failed: Element is not currently visible and so may not be interacted with"收到错误“失败:元素当前不可见,因此可能无法与之交互”
【发布时间】:2016-04-25 05:48:41
【问题描述】:

在尝试点击元素时:

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>"

【问题讨论】:

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

标签: angularjs jasmine protractor


【解决方案1】:

错误是告诉您该元素当前不可见,这就是它无法执行点击的原因。不确定您的应用是如何设置的,是否是 Angular 等。但我建议尝试 2 件事:

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

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多