javascript - Selenium - 元素在点上不可点击

标签 javascript selenium selenium-chromedriver

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

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

最佳答案

您可以执行许多步骤来提高单击不同 UI 元素时的稳定性:

  • 显式等待它出现在DOM中
  • 滚动到元素 View
  • 检查是否可点击

对稳定性有帮助吗?

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

此外,如果您决定覆盖默认值 Actions与更自定义的接口(interface),您可以使用两种类型的点击(例如):click() 将具有所有这些稳定步骤和 fastClick() 这将是没有任何变化的默认点击。

关于javascript - Selenium - 元素在点上不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29508143/

相关文章:

javascript - 单击动态列表创建的元素并显示动态内容

javascript - 你能制作 :after styling dependent on the element value? 吗

java - 为什么我的 ExpectedConditions 命令被忽略? Java 中的 Selenium WebDriver

java - 可在 for 循环内运行

javascript - 通过 Javascript WeakMaps 收集垃圾的缓存

C# Selenium 浏览和上传文件

css - Selenium RC : Selecting elements using the CSS :contains pseudo-class

python - 按 0-10 的顺序轮换代理数组

Python Selenium driver.execute_script WebDriverException : Message: unknown error: call function result missing 'value'

javascript - 动态更改样式表路径在 IE 和 Firefox 中不起作用