【问题标题】:Firefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsExceptionFirefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException
【发布时间】:2019-02-06 12:43:22
【问题描述】:

我遇到了一个奇怪的情况,在 Serenity 的页面上我必须滚动到元素:

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 位)
  • Windows 10
  • 宁静 1.9.30
  • 壁虎驱动 0.21.0

【问题讨论】:

    标签: java selenium firefox geckodriver serenity-bdd


    【解决方案1】:

    此错误消息...

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

    ...暗示 Selenium 由于该元素超出了视口的范围,因此无法将注意力集中在所需的元素上。

    您的主要问题是标识为 webElementWebElement 不在 Viewport 范围内,因此 Selenium 无法移动 焦点 通过moveToElement() 方法在所需元素上。

    解决方案

    一个简单的解决方案是使用executeScript() 方法将所需元素带入视口,然后调用moveToElement() 方法,如下所示:

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

    【讨论】:

      猜你喜欢
      • 2019-08-20
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多