Firefox-org.openqa.selenium.interactions.MoveTargetOutOfBoundsException

Firefox-org.openqa.selenium.interactions.MoveTargetOutOfBoundsException,第1张

Firefox-org.openqa.selenium.interactions.MoveTargetOutOfBoundsException

此错误消息…

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

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

您的主要问题是将 WebElement 标识为 webElement
不在视口中,因此 Selenium
无法通过方法焦点 移到所需元素上

moveToElement()


一个简单的解决方案是使用

executescript()
方法将所需元素 放入视口中 ,然后
moveToElement()
按如下所示调用方法:

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5462819.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存