在 selenium Chrome 驱动程序中出现点击异常时是否仍然可以点击?

Is it possible to click anyway when getting a click exceptions in the selenium Chrome driver?

我们建立网站已经有一段时间了,我正在实施 UI 单元测试。

它在很大程度上依赖于使用 "proxies" 叠加按钮来实现更多功能,例如从一个 iframe 拖动到另一个 iframe。从测试的角度来看,我 want/need 到 "click" 按钮。它应该单击覆盖在其上的代理元素。然后测试可以继续。这在 IE 甚至 Chrome 中都有效,但是当我们在构建服务器上进行测试时,它因错误

而失败

threw exception: System.InvalidOperationException: unknown error: Element is not clickable at point (265, 87). Other element would receive the click: div class="v-iframe-proxy" style="width: 100%; height: 100%;" /div

我希望有一种方法可以忽略这种情况并点击。任何帮助都会很棒。

我相信您在这里有 3 个选择: 1. 使用 JavaScript 执行点击,如下所示:

((JavascriptExecutor) webdriver).executeScript("arguments[0].click()", elementToClick);
  1. 尝试使用new Actions(webdriver).click().build().perform();
  2. 点击
  3. 用 try catch 包围您的点击并继续执行。

我认为您的 UI 测试可以在服务器端的无头浏览器上运行。所以你需要先设置宽度和高度。

如果打印 window 的尺寸,您将看到:0,0

System.out.println(driver.manage().window().getSize());

因此您可以将 window 的大小设置为 1024x600(或任何您想要的大小):

Dimension d = new Dimension(1024,600);
driver.manage().window().setSize(d);