如何处理"MoveTargetOutOfBoundsException"在Selenium WebDriver中 [英] How to handle "MoveTargetOutOfBoundsException" in selenium webdriver
问题描述
当我使用moveToElement时,出现错误" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:元素内的偏移无法滚动到视图中:(0,0):命令持续时间或超时:34毫秒".下面的代码用于此
When I am using moveToElement, I am getting an error "org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Offset within element cannot be scrolled into view: (0, 0): Command duration or timeout: 34 milliseconds". Below code is used for that
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元素(标记为黄色圆圈)悬停并单击编辑(黑色圆圈).
As the below image, first I need to hover i element (which is marked in yellow circle) and click the edit (black circle).
我尝试了以下所有选项.但是没有任何效果.它的位置是动态的.
I have tried all below options .But nothing is working. The position of it is dynamic.
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)");
和
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
请帮助我.
推荐答案
如果在IE浏览器中遇到上述异常.请按照以下步骤操作:
if you are getting the above mentioned exception in IE browser. Please follow the below steps:
- 返回IE并检查缩放级别是否设置为100%
- 如果将缩放级别设置为100%,并且您的网络应用仅在浏览器的一半中显示,则说明它存在分辨率问题,
- 转到您的桌面并更改屏幕分辨率:在我的情况下,1366 * 768有效.
- 现在返回IE浏览器,将缩放级别设置为100(它将根据屏幕分辨率重置).
- 现在,请确保您的网络应用程序能够像在其他浏览器中看到的那样显示.
最后再次运行您的代码,现在您应该不会看到此错误. :)
Finally run your code again and now you should not see this error. :)
这篇关于如何处理"MoveTargetOutOfBoundsException"在Selenium WebDriver中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!