java-client icon indicating copy to clipboard operation
java-client copied to clipboard

AndroidDriver returns empty element text/value with appium java-client 8.1.1

Open dawsze opened this issue 3 years ago • 5 comments

Description

I've just upgraded appium java-client from 7.6.0 to 8.1.1. Tests on AndroidDriver cannot get proper element value or text (element.getAttribute("value") | element.getText()). These methods returns only empty values. IOSDriver works fine.

Moreover if I change AndroidDriver to RemoteWebdriver everything is back to normal and methods returns proper element text/value.

Tested on:

  • Huawei P9 Lite 2017 (Android 7.0, EMUI 5.0) - Real Device
  • Huawei P10 Lite (Android 7.0, EMUI 5.1) - Real Device
  • Samsung S22 Ultra (Android 12) - Real Device (BrowserStack)
  • Samsung A51 (Android 10) - Real Device (BrowserStack)

Environment

  • Java client build version or git revision if you use some snapshot: 8.1.1
  • Appium server version or git revision if you use some snapshot: 1.22.3 (Started by CLI)
  • Desktop OS/version used to run Appium (Server): MacOS Monterey 12.4
  • npm version: 8.9.0
  • Node.js version: v18.2.0

Code To Reproduce Issue [ Good To Have ]

TestClass: https://gist.github.com/dawsze/0b87efd7cb8ab3a3b6db86af3bd3493e

pom.xml: https://gist.github.com/dawsze/43cb5c93237f88c1164528c6840b35d9

Exception Stacktraces

https://gist.github.com/dawsze/0684f0fd0566db315de5d9c096287998

Link To Appium Logs

https://gist.github.com/dawsze/893a277714e9b9d3339268f620b39d05

dawsze avatar Jun 15 '22 11:06 dawsze

Moreover if I change AndroidDriver to RemoteWebdriver everything is back to normal and methods returns proper element text/value.

Please provide the server log you get while using vanilla RemoteWebDriver (and returning the expected value). I assume there might be a difference between Chromedriver working in JWP and W3C protocols.

mykola-mokhnach avatar Jun 15 '22 12:06 mykola-mokhnach

Server log: https://gist.github.com/dawsze/4781ed948ab629201c39157e86a9de18

dawsze avatar Jun 20 '22 09:06 dawsze

I can observe that the previous client version was passing some hacky javascript () in order to fetch the element value while the current one simply calls the corresponding chromedriver endpoint. From my perspective the latter one is the correct approach and if no value is returned then it must be reported as chromedriver issue. In the worst case you could just copy that hacky script and use it in your code to mimic the legacy behaviour.

mykola-mokhnach avatar Jun 20 '22 12:06 mykola-mokhnach

Found this ticket at chromedrivers community: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3820 but i don't know it's related with my issue.

Anyway, reffering to comments, I changed UiAutomator2Options to ChromeOptions and set two additional capabilities:

  • setExperimentalOption("w3c",false);
  • setBrowserVersion("");

which seems to work as workaround.

Does this change may affect to any others code parts in whole project? (I mean appiums may work in strange ways in example) I've done few simple tests and all did pass but I have few "big" projects which relate to each other so test it all may took a time

dawsze avatar Jun 21 '22 08:06 dawsze

Appium works as a simple proxy in case of chromedriver. We don't try to add any logic on top of that functionality. IMHO disabling W3C mode might work as a temporary workaround, but in the longer perspective JWP protocol will be completely deprecated.

mykola-mokhnach avatar Jun 21 '22 09:06 mykola-mokhnach