appium: 🐞 bug: Appium Hybrid Android app show different x,y values in element.rect compares to Appium Inspector (webView context))

Is there an existing issue for this?

  • I have searched the existing issues

Appium Version

2.19.0

Appium Host Type

Command Line

Are you using Appium components not maintained by the Appium team?

No response

Is this issue reproducible using the latest components?

  • I confirm the issue is still reproducible with the latest component versions

Current Behavior

I successfully find my element with driver xpath find, element = driver.find_element('xpath', 'my_element_xpath') When I print to log element.rect to log I get a differnt x, y coordinates: RECT {'height': 35, 'width': 142, 'x': 19.604167938232422, 'y': 19.604167938232422}

Compares to what the Appium Inspector is showing:

Image

I need the Inspector values since I perform long click with execute_script and longClickGesture method.

Expected Behavior

Inspector and test element.rect should show the same x,y values

Appium Log

https://github.com/bwomsm1/AppiumLogs/blob/master/coords.log

Environment Details

Minimal Reproducible Example

element = driver.find_element('xpath', 'my_element_xpath') `print(element.rect)

Further Information

I also found that the following tries: element.location using getBoundingClientRect are showing the same values as element.rect

About this issue

Most upvoted comments

I am fairly confident that getting those (29, 65) values outside of the Inspector would require non-trivial calculations. If anything, it’s not always the case that the values you see in the Inspector will be correct in the first place (I saw this in my own tests earlier today in Chrome). They are only there to attempt overlaying webview elements on the native screenshot, and I do not recommend relying on their exact values.

At the same time, the (19, 19) values you receive through queries like element.rect, element.location and so on are indeed correct with respect to the webview window bounds. These queries use standard WebDriver endpoints, but in webview context they have no information about any external contexts, which is why the values they return will not work when applied directly in the native context.

Because of this, in your situation I can see two approaches: either rely on the webview context elements instead of their coordinates (like in my earlier suggestion), or use coordinates/elements retrieved exclusively through native context.