在Selenium中执行WebElement#click()之前如何检查元素是否重叠 [英] How do I check if there is an overlapping element before executing WebElement#click() in Selenium

查看:236
本文介绍了在Selenium中执行WebElement#click()之前如何检查元素是否重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某个元素与另一个元素重叠(例如

If there is an element that is overlapped by another element (like on this internal Selenium test page), I get an ElementClickInterceptedException. It looks like I cannot check this beforehand, only after the exception is thrown via the exception message.

这与进行点击传递无关(我可以简单地通过JavaScript强制它,或者如果重叠只是暂时的,则等待),而是关于检查重叠以防止调用WebElement#click().这可能吗?

It's not about making the click pass (I can simply force it via JavaScript or wait if the overlap is only temporary), but about checking for the overlap to prevent the invocation of WebElement#click(). Is this possible?

推荐答案

您无法事先检查,但可以做的是将try-catch添加到click方法中并捕获ElementClickInterceptedException,然后重试单击,直到不再抛出异常或发生超时.

You can't check beforehand but what you can do is add a try-catch to a click method and catch the ElementClickInterceptedException and retry the click until the exception is no longer thrown or a timeout occurs.

这篇关于在Selenium中执行WebElement#click()之前如何检查元素是否重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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