Selenium - 元素在点上不可点击 [英] Selenium - Element is not clickable at point

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

问题描述

我正在使用selenium作为测试脚本。我收到以下错误,随机发生此错误。当我跑10次时,我得到了大约两次。所以它不是真正可重复的。有谁知道为什么会这样?我试图点击的元素在浏览器中肯定是可见的并且不会移动,因此不需要调整大小或拖动元素。我正在使用chrome webdriver,并且我阅读了其他故障排除策略(调试元素在点错误时无法点击,并且它们似乎与我的问题无关。我也等了足够的时间。

I am using selenium for test script. I am getting following error and this error randomly occur. When I run 10 times, I get this about twice. So it's not really reproducible. Does anyone know why this is happening? the element I am trying to click is definitely visible in the browser and doesn't move around so there is no need to resize or drag element. I am using chrome webdriver and I read other troubleshooting strategies(Debugging "Element is not clickable at point" error) and they don't seem relevant to my issue. I waited enough time as well.

UnknownError: unknown error: Element is not clickable at point (167, 403). Other element would receive the click: <div class="leftMasterBackground"></div>


推荐答案

您可以按顺序执行多个步骤在点击不同的UI元素时提高稳定性:

There are a number of steps you can do in order to improve the stability while clicking on different UI elements:


  • 明确等待存在在DOM中

  • 滚动进入元素视图

  • 检查是否可点击

  • Explicitly wait for it's presence in the DOM
  • Scroll into the element view
  • Check if clickable

它是否有助于稳定性?

WebDriverWait wait = new WebDriverWait(driver, 3)
JavascriptExecutor js = ((JavascriptExecutor) driver)

//presence in DOM
wait.until(ExpectedConditions.presenceOfElement(By.id("ID")));

//scrolling
WebElement element = driver.findElement(By.id("ID")));  
js.executeScript("arguments[0].scrollIntoView(true);", element);

//clickable
wait.until(ExpectedConditions.elementToBeClickable(By.id("ID")));

此外,如果您决定覆盖默认动作界面有更多自定义的界面,你可以使用两种类型的点击(例如): click()这将是所有这些稳定性步骤和 fastClick()这将是默认点击没有任何变化。

Further, if you will decide to override the default Actions interface with more customized one, you can use two type of clicks (for example): click() which will have all those stability steps and fastClick() which will be the default clicking without any varification.

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

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