Selenium MoveTargetOutOfBoundsException even after scrolling to element

Ľubomír :
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?

Batuhan Kilic :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=132034&siteId=1