Shino
Shino

Reputation: 125

How to handle "MoveTargetOutOfBoundsException" in selenium webdriver

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();

and the web elements are

@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;

As the below image, first I need to hover i element (which is marked in yellow circle) and click the edit (black circle).

enter image description here

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)");

and

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

Please help me.

Upvotes: 2

Views: 23004

Answers (3)

Karthik Lakshmanrao
Karthik Lakshmanrao

Reputation: 11

if you are getting the above mentioned exception in IE browser. Please follow the below steps:

  1. Go back to IE and check zoom level is set to 100%
  2. If zoom level is set to 100% and your web app is displaying only in half of the browser then its a resolution problem,
  3. Go to your desktop and change the screen resolution : in my case 1366*768 worked.
  4. Come back to IE browser now set the zoom level to 100 (It will be reset according to screen resolution).
  5. Now make sure your web app is appearing as you are seeing in other browsers.

Finally run your code again and now you should not see this error. :)

Upvotes: 0

Shino
Shino

Reputation: 125

This solution worked for me

((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();");

Upvotes: 0

JeffC
JeffC

Reputation: 25611

I would separate the different actions. I would hover using Actions then do a "normal" click().

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

Upvotes: 2

Related Questions