当我使用 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 元素(以黄色圆圈标记)上,然后单击编辑(黑色圆圈)。
我已经尝试了以下所有选项。但没有任何效果。它的位置是动态的。
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/