Firefox-org.openqa.selenium.interactions.MoveTargetOutOfBoundsException [英] Firefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException

查看:227
本文介绍了Firefox-org.openqa.selenium.interactions.MoveTargetOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一种奇怪的情况,在宁静"页面上,我必须滚动到该元素:

I have faced a weird situation, where on the page in Serenity I have to scroll to the element:

withAction().moveToElement(webElement).perform();

,此方法会抛出某些元素:

and this method for some elements throws:

org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: 
(377.375, 958.3999938964844) is out of bounds of viewport width (1268) and height (943)


它仅在Firefox中发生(Chrome可以正常运行).而且,几乎所有其他我使用相同方法的地方都运行良好.所有元素只是按钮,输入字段等常用元素.


It happens only in Firefox(Chrome works fine). Moreover almost all other places, where I'm using the same method are working well. All elements are just usual elements like buttons, input fields, etc.

有人知道如何在Firefox中解决此问题吗?

Does anybody know how to fix this in Firefox?

我有:

  • Firefox 61.0.2(64位)
  • Windows 10
  • 宁静1.9.30
  • Geckodriver 0.21.0

推荐答案

此错误消息...

org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: 
(377.375, 958.3999938964844) is out of bounds of viewport width (1268) and height (943)

...表示 Selenium 无法聚焦在所需的元素上,因为该元素超出了视口的范围.

...implies that Selenium was unable to focus on the desired element as the element was out of bounds of the viewport.

您的主要问题是标识为 webElement WebElement 来自视口,因此不能通过moveToElement()方法将焦点移至所需元素上.

Your main issue is the WebElement identified as webElement is out of Viewport so Selenium can't move the focus on the desired element through moveToElement() method.

一个简单的解决方案是使用executeScript()方法将所需元素放入视口中,然后按以下方式调用moveToElement()方法:

A simple solution would be to use the executeScript() method to bring the desired element within the viewport and then invoke moveToElement() method as follows:

WebElement myElement = driver.findElement(By.xpath("xpath_of_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", myElement);
withAction().moveToElement(webElement).perform();

这篇关于Firefox-org.openqa.selenium.interactions.MoveTargetOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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