【问题标题】:How to handle "MoveTargetOutOfBoundsException" in selenium webdriver如何在 selenium webdriver 中处理“MoveTargetOutOfBoundsException”
【发布时间】:2016-03-14 13:37:59
【问题描述】:

当我使用 moveToElement 时,我收到错误“org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:元素内的偏移量无法滚动到视图中:(0, 0):命令持续时间或超时:34 毫秒”。下面的代码用于此

WebDriverWait waitForEditI = new WebDriverWait(driver, 20);     
waitForEditI.until(ExpectedConditions.elementToBeClickable(editContactI));
Actions action = new Actions(driver);
    action.moveToElement(editContactI).moveToElement(editContactIEdit).click().build().perform();

网页元素是

@FindBy(how = How.CSS, using = "div#evy_aboutme_content_id08  div.evy_edit_overflow > div.evy_rltn_icon2 i")    
  WebElement  editContactI;

  @FindBy(how = How.CSS, using = "div#evy_aboutme_content_id08  div.evy_aboutme_education_content.ng-scope   a:nth-child(1)")   
 WebElement editContactIEdit;

如下图,首先我需要将 i 元素(黄色圆圈标记)悬停并点击编辑(黑色圆圈)。

我已经尝试了以下所有选项。但没有任何效果。它的位置是动态的。

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)");

Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();

请帮助我。

【问题讨论】:

    标签: selenium selenium-webdriver


    【解决方案1】:

    我会把不同的动作分开。我会使用Actions 悬停,然后执行“正常”click()

    Actions builder = new Actions(driver);
    builder.moveToElement(editContactI).perform();
    driver.findElement(editContactIEdit).click();
    

    【讨论】:

    • 怎么不工作了?怎么了?你有错误吗?某些部分是起作用还是根本不起作用?
    • 我遇到了同样的错误...“元素内的偏移量无法滚动到视图中:”
    • 听起来你需要做一些调试。我的猜测是您的editContactI 定位器不太正确或需要调整。我会首先确保您通过执行driver.findElement(editContactI).getAttribute("outerHTML") 之类的操作来获得您想要的元素。
    • 杰夫。我是这样修复的 ((JavascriptExecutor)driver).executeScript("$('div#evy_aboutme_content_id08 div.evy_edit_overflow > div.evy_rltn_icon2 i').hover();"); ((JavascriptExecutor)driver).executeScript("$('div#evy_aboutme_content_id08 div.evy_aboutme_education_content.ng-scope a:nth-child(1)').click();");
    【解决方案2】:

    这个解决方案对我有用

    ((JavascriptExecutor)driver).executeScript("$('div#evy_aboutme_content_id08  div.evy_edit_overflow > div.evy_rltn_icon2 i').hover();");
        ((JavascriptExecutor)driver).executeScript("$('div#evy_aboutme_content_id08  div.evy_aboutme_education_content.ng-scope   a:nth-child(1)').click();");
    

    【讨论】:

      【解决方案3】:

      如果您在 IE 浏览器中遇到上述异常。请按照以下步骤操作:

      1. 返回 IE 并检查缩放级别是否设置为 100%
      2. 如果缩放级别设置为 100%,并且您的 Web 应用程序仅在一半的浏览器中显示,那么这是分辨率问题,
      3. 转到您的桌面并更改屏幕分辨率:在我的情况下 1366*768 有效。
      4. 回到 IE 浏览器,现在将缩放级别设置为 100(它将根据屏幕分辨率重置)。
      5. 现在请确保您的 Web 应用程序与您在其他浏览器中看到的一样。

      最后再次运行您的代码,现在您应该不会看到此错误。 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-13
        • 2012-04-14
        • 2020-06-11
        • 2014-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多