量角器中的元素不可单击 [英] Element is not clickable in Protractor

查看:56
本文介绍了量角器中的元素不可单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与模式弹出窗口中的任何元素交互时,我遇到问题.我正在使用ChromeDriver 2.46,并且所有涉及模式弹出窗口的测试在Chrome 74上均失败.

I am facing issue while interacting with any element in a modal popup. I am using ChromeDriver 2.46 and all tests which involves modal popup fails on Chrome 74.

我遇到错误

元素不可点击.其他元素将获得点击

我尝试使用 scrollToTop scrollToElement visibilityOf ,但是没有任何效果.有人遇到过类似的问题吗?

I have tried with scrollToTop, scrollToElement and visibilityOf but nothing worked. Has anyone faced similar issue?

推荐答案

为您附加html和完整的错误堆栈

Attach you html, and full error stack

同时这是我的假设,您的问题很可能是90%

Meanwhile here is my assumption which is 90% likely what your problem is

让我们假设您的html类似于

Lets assume your html is something like

<div>
  <button></button>
</div>

您的按钮可见...但是 div 元素也可见.但是因为包装按钮,所以它在按钮上方(z索引较高).这就是为什么当您单击按钮时,div会获得此单击,而量角器不会发生这种情况.失败了

your button is visible... but so is div element. BUT because wraps the button, it is above the button (has higher z-index). That's why when you click button, div gets this click, which protractor doesn't let happen. And fails

在这种情况下,只需使用js click

In this case just simply use js click

browser.executeScript(
  "arguments[0].click();",
  $element.getWebElement() // substitute $element to your elementFinder
)

这将起作用,因为无论可见度和页面布局如何,元素都会获得点击

this will work because element gets the click regardless of visibility and the page layout

这篇关于量角器中的元素不可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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