[英]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: 我遇到了一个奇怪的情况,在Serenity的页面上我必须滚动到元素:
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)
It happens only in Firefox(Chrome works fine). 它只发生在Firefox(Chrome工作正常)。 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. 所有元素都只是常用元素,如按钮,输入字段等。
Does anybody know how to fix this in Firefox? 有人知道如何解决这个问题吗?
I have: 我有:
This error message... 此错误消息...
org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:
(377.375, 958.3999938964844) is out of bounds of viewport width (1268) and height (943)
...implies that Selenium was unable to focus on the desired element as the element was out of bounds of the viewport. ...暗示Selenium无法专注于所需的元素,因为该元素超出了视口的范围。
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. 你的主要问题是标识为webElement的WebElement超出视窗所以硒无法通过移动焦点所需的元素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: 一个简单的解决方案是使用executeScript()
方法在视口中引入所需的元素,然后调用moveToElement()
方法,如下所示:
WebElement myElement = driver.findElement(By.xpath("xpath_of_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", myElement);
withAction().moveToElement(webElement).perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.