2
new Actions(data).moveToElement(element,x,y).perform();

This code worked find with: Selenium 3.8.1, Chrome 63, chromedriver 2.3.8

After finally upgrading to: Selenium 3.14 , Chrome 75, chromedriver 75.0.3770.9

I am getting error:

org.openqa.selenium.interactions.MoveTargetOutOfBoundsException

I was suggested this:

With Chromedriver's switch to w3c compliance in version 75, you now have to scroll any elements into view before using actions on them

So I added this code (isVisibleInViewport is from here)

  private boolean isVisibleInViewport(WebElement element) {
      return (boolean)((JavascriptExecutor)data).executeScript(
            "var elem = arguments[0],                 " +
            "  box = elem.getBoundingClientRect(),    " +
            "  cx = box.left + box.width / 2,         " +
            "  cy = box.top + box.height / 2,         " +
            "  e = document.elementFromPoint(cx, cy); " +
            "for (; e; e = e.parentElement) {         " +
            "  if (e === elem)                        " +
            "    return true;                         " +
            "}                                        " +
            "return false;                            "
            , element);
  }

public void moveToElement(WebElement element, int x,int y){
    if (!isVisibleInViewport(element)) ((JavascriptExecutor) data).executeScript("arguments[0].scrollIntoView();", element);
    new Actions(data).moveToElement(element,x,y).perform();
}

However I am still getting same error:

org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: move target out of bounds
  (Session info: chrome=75.0.3770.100)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'TEST_VIRTUAL_114', ip: '192.168.215.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.90 (a6dcaf7e3ec6f..., userDataDir: C:\Users\TestVirtualPC\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:63560}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

So what is the problem then?

Ľubomír
  • 1,075
  • 1
  • 12
  • 20
  • Have you cross checked the x and y values that you are passing, with the application x,y? Are they matching? – supputuri Jun 22 '19 at 22:38
  • The thing it is was working before and page is still same.. only thing that was changed is selenium, chrome and chromedriver version – Ľubomír Jun 23 '19 at 08:20
  • 1
    I have a similar issue. Using Chrome 75 and chromedriver 74 it works fine. Switching to chromedriver 75.0.3770.8 raises the exception. – Christian Jun 24 '19 at 15:20
  • See also (presumably same question for Python) [python - MoveTargetOutOfBoundsException problem with chromedriver version >74 - Stack Overflow](https://stackoverflow.com/questions/59819502/movetargetoutofboundsexception-problem-with-chromedriver-version-74) – user202729 Dec 09 '21 at 09:12

2 Answers2

3

I'm not sure if you are facing with the same problem but I had a similar problem when I update my chromedriver to version75.

Before I was using offsets from the top-left corner and it was working fine for previous versions of chromedriver.

But from now on(Version75) I have to use offsets from the center of web element.

Calculating the coordinates from the center of web element solved my problem.

0

The below worked for me.

WebElement element = driver.findElement(locator);

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

Originally posted here:

https://github.com/mozilla/geckodriver/issues/776#issuecomment-353595601

Greenonline
  • 1,330
  • 8
  • 23
  • 31
davomarti
  • 1
  • 1