简体   繁体   English

Firefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException

[英]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: 我有:

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

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. 你的主要问题是标识为webElementWebElement超出视窗所以无法通过移动焦点所需的元素moveToElement()方法。

Solution

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.

相关问题 org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: (x, y) 越界,而鼠标悬停与 GeckoDriver Firefox Selenium - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: (x, y) is out of bounds while MouseHover with GeckoDriver Firefox Selenium org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:使用 Selenium Chrome 和 java.version:'16.0.2' 将目标移出边界 - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: move target out of bounds using Selenium Chrome and java.version: '16.0.2' java.lang.ClassCastException: org.openqa.selenium.firefox.FirefoxDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen - java.lang.ClassCastException: org.openqa.selenium.firefox.FirefoxDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen 收到错误“org/openqa/selenium/interactions/HasInputDevices” - Getting error "org/openqa/selenium/interactions/HasInputDevices" “HasInputDevices”位于“/ org / openqa / selenium / interactions”但它仍然在查看“/ org / openqa / selenium /” - “HasInputDevices” is located at “/org/openqa/selenium/interactions” but it is still looking at “/org/openqa/selenium/” 启动Firefox时,org.openqa.selenium.firefox.NotConnectedException - org.openqa.selenium.firefox.NotConnectedException when starting Firefox 不能访问org.openqa.selenium.firefox.FirefoxDriver类型 - The type org.openqa.selenium.firefox.FirefoxDriver is not accessible 导入org.openqa.selenium.firefox.FirefoxDriver无法解析 - The import org.openqa.selenium.firefox.FirefoxDriver cannot be resolved Firefox 驱动程序失败并出现 org.openqa.selenium.SessionNotCreatedException: - Firefox Driver fails with org.openqa.selenium.SessionNotCreatedException: 我已经导入了 org.openqa.selenium.interactions.Actions 但仍然抛出错误 Actions can not resolve to a variable - I have imported org.openqa.selenium.interactions.Actions but still throwing error Actions can not resolved to a variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM