代码之家  ›  专栏  ›  技术社区  ›  Andrei Suvorkov

火狐-org.openqa.selenium网站.interactions.MoveTargetAutofBoundsException异常

  •  1
  • Andrei Suvorkov  · 技术社区  · 6 年前

    我遇到了一个奇怪的情况,在平静的页面上,我不得不滚动到元素:

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

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

    这只发生在Firefox中(Chrome可以正常工作)。此外,几乎所有其他地方,在我使用相同的方法都工作得很好。所有元素都是常用的元素,比如按钮、输入字段等。

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

    我有:

    • Firefox 61.0.2(64位)
    • 视窗10
    • 宁静1.9.30
    • 壁虎河0.21.0
    1 回复  |  直到 6 年前
        1
  •  4
  •   undetected Selenium    6 年前

    此错误消息。。。

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

    …意味着

    你的主要问题是 网络元素 已超出 Viewport 所以 不能移动 集中 moveToElement() 方法。

    解决方案

    一个简单的解决方案是使用 executeScript() 视口 然后调用 方法如下:

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