bug: Find Element by Image fails randomly
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Current Behavior
We have a suite of tests for Android that use the find element by image, on static images, which can all be found, but sometimes it fails randomly with the bellow error.
NoSuchElementException: Message: An element could not be located on the page using the given search parameters. Stacktrace: NoSuchElementError: An element could not be located on the page using the given search parameters. at ImageElementFinder.findByImage (/Users/username/.appium/node_modules/@appium/images-plugin/lib/finder.js:230:13) at ImageElementPlugin._find (/Users/username/.appium/node_modules/@appium/images-plugin/lib/plugin.js:61:12) at ImageElementPlugin.findElement (/Users/username/.appium/node_modules/@appium/images-plugin/lib/plugin.js:45:12) at /usr/local/lib/node_modules/appium/lib/appium.js:722:18 at AppiumDriver.executeWrappedCommand (/usr/local/lib/node_modules/appium/lib/appium.js:762:16) at AppiumDriver.executeCommand (/usr/local/lib/node_modules/appium/lib/appium.js:684:17) at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:346:19)
After getting the above error, subsequent runs of the same suite will get the bellow error.
WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Cannot read properties of undefined (reading ‘match’) Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot read properties of undefined (reading ‘match’) at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:956:9) at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:435:35)
This second error will always appear until the server is restarted and the images will be found again until the first error happens again.
Expected Behavior
The images are found or not consistently and the server is able to handle the exception without the needing a restart.
Minimal Reproducible Example
We are providing an png image into the bellow function, which will then be converted to base64.
def _find_by_image(self, img_path: str):
driver = self._get_driver_instance()
with open(img_path, 'rb') as i_file:
b64_data = base64.b64encode(i_file.read()).decode('UTF-8')
return driver.find_element(by=AppiumBy.IMAGE, value=b64_data)
Regarding steps is only needed to execute the find_by_image a few times.
Environment
- Operating system: MacOS/Windows
- Appium CLI version (output of
appium --version
): 2.0.0-beta.46 - Node.js version (output of
node --version
): v16.14.2 npm
version (output ofnpm --version
): 8.17.0
- Appium CLI version (output of
- Appium driver(s) and their version(s):
- uiautomator2@2.10.2
- Appium plugin(s) and their version(s):
- device-farm@2.0.0-beta.4 [installed (NPM)]
- appium-dashboard@v1.0.0-beta.13 [installed (NPM)]
- images@1.3.7 [installed (NPM)]
- Platform and version under test:
- Android 12
- Real device or emulator/simulator:
- Redmi Note 9T
Link to Appium Logs
https://gist.github.com/jorgoncalves/8a163bbcd77498cab0a02a9e4f3b520e
Futher Information
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:12
Top GitHub Comments
I see.
really looks like a bug in the plugin to me and should be checked first.
Closed because of no response. The patch is currently merged to master, but not published. The only way to try it is to run the server from source or wait until the next version is published