selenium - 如何在selenium webdriver中处理 "MoveTargetOutOfBoundsException"

标签 selenium selenium-webdriver

当我使用 moveToElement 时,出现错误“org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:元素内的偏移量无法滚动到 View 中:(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 元素(以黄色圆圈标记)上,然后单击编辑(黑色圆圈)。

enter image description here

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

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

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

请帮助我。

最佳答案

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

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

关于selenium - 如何在selenium webdriver中处理 "MoveTargetOutOfBoundsException",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35989076/

相关文章:

python - 如何使用 selenium 在 Twitter 登录页面中单击下一步 - Python

javascript - Protractor TAB 键已停止改变焦点,现在正在添加空格

python - 如何在docker中运行selenium-side-runner?

python - 如何点击单选按钮(我读过以前的问题)python?

selenium - 如何使用 Selenium WebDriver 打开新选项卡并启动链接?

firefox - 无法通过ssh启动selenium浏览器

python - 使用 Python Selenium 从下拉菜单中获取当前 <select> 值

ruby-on-rails - 如何测试自定义 uploader 是否有效?

java - 在 testng 中使用 selenium 中的函数时如何保持代码干燥?

python - 如何抓取与特定期刊/文章论文的每位教授相关的从属关系