New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
offsets are from the center of element instead of from the top-left corner #789
Comments
|
The problem is the x,y offsets I used for old firefox driver and chromedriver don't work for geckodriver. So I get 'indexoutofbounds' exception when using the x,y offsets that I used for earlier versions of the driver. I will try to come up with a reproducible generic test case. |
Sure, but please note that neither FirefoxDriver (from Selenium) or chromedriver are implementations of the WebDriver specification. It would be useful to see a trace-level log. |
Here is a simple code to demonstrate the problem. The actual application I automate needs drawing that is why I rely on the Action.moveToElement but I just picked this one to demo the problem. System.setProperty("webdriver.gecko.driver", "/Users/Downloads/geckodriver"); Please run this code using geckdriver and then comment out the FirefoxDriver and use the chromedriver line by uncommenting. Notice that the moveToElement works fine for chrome(it worked in old firefox driver as well) but in geckodriver it fails as the offset is computed from the center of the element instead of from top-left corner. |
I don’t know what That it “worked before” is not a great bug. |
Below is the log:
|
With the old protocol (Wire) the command to move the cursor was https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidmoveto But with the new W3C specification and implementation in marionette, moving the cursor to an element now requires a composite action where the offset is relative to the element's center: https://w3c.github.io/webdriver/webdriver-spec.html#dfn-dispatch-a-pointermove-action
It seems that the specification was updated to accommodate the implementation of marionette which was already relative to center even before Firefox 45. So this behavior is by design. The current api doesn't provide a way to directly move the cursor with an offset relative to the top-left corner. It would make much more sense to provide an offset relative to the top-left corner especially when testing canvas. That said, I would still consider this an issue, first because it breaks a previous feature and second because this change doesn't bring any value to the api. |
I think this is a fair point. @florentbr, do you want to raise an issue against the specification? |
I can add some info based on Selenium Java test suite, there is a test against this page: https://github.com/SeleniumHQ/selenium/blob/master/common/src/web/mousePositionTracker.html
The result is "78, 191" instead of expected "95, 195" Trace log:
|
This comment has been minimized.
This comment has been minimized.
@andreastt based on your comment from July last year (#789 (comment)) it looks like that no spec issue has been filed, or? |
I do not see any changes from FF or on geckodriver. I am using geckodriver 24 with FF 65.0.2 I feel the solution to this problem has been left hanging in lot of places where I see similar questions. We resolved this situation by,
From this if you want to move to any point at the element. you may want to
Which will click at the point where you are anticipating. |
@raguravindran I assume you didn't run chromedriver in w3c mode? It should fail the same way. Also please read the documentation of geckodriver and use the following capability for now: |
The bug is in selenium. The drivers for Chrome and Edge Dev (chromium), since version 75, both comply with the w3c. Selenium need to update their javadocs to say that it's from the centre. It would probably be too much of a faff to fix it in the selenium code because they won't know the dimensions of the element. |
There is precedence for high-level Selenium client commands to run extra steps to alter the behaviour of commands. So it’s technically possible to mitigate the difference in behaviour for Selenium users by the clients first getting the bounding box of the element and then changing the click point using an action primitive. That said, if recent Chrome and Edge drivers are aligned with geckodriver’s behaviour perhaps it is not a priority. |
|
Is anyone still having issues with this particular behavior? If yes please report and provide a testcase + trace log. Otherwise I'm going to close this issue soon. Thanks. |
Due to lack of response I'm going to close this issue for now. I'm happy to reopen if there are still use cases out there which do not work with the center of element approach. |
In order to help us efficiently investigate your issue, please provide the following information:
Platform and application details
Steps to reproduce
In org.openqa.selenium.interactions.Actions the x, y offsets for moveToElement has been Offset from the top-left corner.
But with geckodriver I'm getting:
Jun 16, 2017 5:55:05 PM org.openqa.selenium.interactions.Actions moveToElement
INFO: When using the W3C Action commands, offsets are from the center of element
Has the offset changed to center of element instead of top-left corner? While chromedriver, old firefox driver and safaridriver calculates the offset from top-left corner is this a bug in geckodriver?
Reproducable testcase:
Try moveToElement method in org.openqa.selenium.interactions.Actions
It differs between old firefox drivers.
A trace level log:
Jun 16, 2017 5:55:05 PM org.openqa.selenium.interactions.Actions moveToElement
INFO: When using the W3C Action commands, offsets are from the center of element
The text was updated successfully, but these errors were encountered: