Selenium MoveTargetOutOfBoundsException

6,959 views
Skip to first unread message

Meeee

unread,
Jun 23, 2019, 5:30:20 AM6/23/19
to Selenium Users
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?

And why do we have to now check if element is in view, scroll to element if it is not and then we can move mouse to it? 

That is making only things more complicated and not easier with new versions.... ???

Joe Ward

unread,
Jun 23, 2019, 5:49:42 AM6/23/19
to seleniu...@googlegroups.com
Bringing things into compliance with the spec is about consistency with agreed upon standards, not reverse compatibility. 

Are you sure your snippet of code is correct? if you are getting the same error it suggests not. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3a95f647-de9f-42e4-96bf-f155152130e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Meeee

unread,
Jun 23, 2019, 6:18:13 AM6/23/19
to Selenium Users
Well everything was working back in 3.8.1, page did not change, only thing that I changed was Selenium, Chrome and chromedriver....

I do not know if my code is correct or not, because there is no internal api to scroll to element if it is not visible in view ? You have to do it with JavaScript ...

Yeah everything is nice about following agreed standards, but what about usability for users? Now you have more things to check (without internal api), so maybe extending api with Action like scrollAndMoveToElement() would be nice, because usability is now more complicated then it used to be. 
So why following standards and making it harder for users to use selenium in tests?

Ryan Cribb

unread,
Jun 28, 2019, 12:20:28 AM6/28/19
to Selenium Users
I am also having issues, it seems that the way Actions works on the page has changed in chromedriver 75. Previously actions would move to 0,0 by default and now it moves to the center of the object. This causes you to be out of bounds if you were already compensating for this. I also noticed that the actions class is significantly slower than before as well. Forcing chromedriver 74 resolves the issue and speeds up my test suite by about 45 minutes (usual run is about 9 hours) compared to 75. 
Reply all
Reply to author
Forward
0 new messages