Inconsistent behavior of getting text from an element
See original GitHub issueThe problem
I’ve found there are some inconsistent behavior related to an element including new lines.
- Some locator with new lines succeeds, but others fail.
- Even the same element returns different texts when found by a different locator.
Environment
- Appium version (or git revision) that exhibits the issue: 1.21.0
- Last Appium version that did not exhibit the issue (if applicable): -
- Desktop OS/version used to run Appium: macOS 10.15 Catalina
- Node.js version (unless using Appium.app|exe): 12.13.1
- Npm or Yarn package manager: npm 6.12.1
- Mobile platform/version under test: iOS 14 / Android 10.0
- Real device or emulator/simulator: iOS simulator / iOS real device / Android emulator
- Appium CLI or Appium.app|exe: Appium CLI
Details
Suppose we have a dialog whose message contains a new line like this (This is iOS case)
We expect that we can use same text in locators to find the element, but actually the required locator is different between -ios class chain
and xpath
. New lines in xpath is replaced with a space. But it’s not the case on Android.
Besides, even the returned text is different. The second phenomenon looks especially strange for me.
Is it an intentional result? We’d like to know what is the expected behavior.
Platform | Locator strategy | Find element result | Get text result |
---|---|---|---|
iOS | -ios class chain | Succeeds only when the locator contains a new line | Contains a new line |
iOS | xpath | Succeeds only when the new line is replaced with a space | Doesn’t contain a new line |
Android | xpath | Succeeds only when the locator contains a new line | Contains a new line |
Link to Appium logs
- [iOS real device] (https://gist.github.com/nkns165/1d69ebf66a85e767833be17087755144)
- [Android emulator] (https://gist.github.com/nkns165/d39009a3d43ae7ba2acf5fedcad7018f)
Code To Reproduce Issue [ Good To Have ]
I’m sorry it’s difficult to provide it immediately because the code is tightly connected with our own system. If detail investigation using actual code is required, please let me know.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I think at this stage it’s safer to leave minor inconsistencies between XPath across platforms. It’s not as if XPath queries generally work cross-platform anyway (since each platform has its own unique set of class names). The way Android and iOS render element text to the accessibility systems is also in no way guaranteed to be the same.
Thank you for your quick responses! Then we will develop based on the current behavior.