question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Find Element by Image fails randomly

See original GitHub issue

Is 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 of npm --version): 8.17.0
  • 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:closed
  • Created 10 months ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
mykola-mokhnachcommented, Nov 9, 2022

I see.

2022-11-09 12:14:31:879 [AndroidUiautomator2Driver@87f9 (128a8d3e)] Encountered internal error running command: TypeError: Cannot read properties of undefined (reading ‘match’) 2022-11-09 12:14:31:879 [AndroidUiautomator2Driver@87f9 (128a8d3e)] at condition (/Users/username/.appium/node_modules/@appium/images-plugin/lib/finder.js:205:25)

really looks like a bug in the plugin to me and should be checked first.

0reactions
mykola-mokhnachcommented, Nov 18, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Here's How I Solved a Weird Bug Using Tried and True ...
At first, this looks like a CSS issue. Some styles might be applied on a hover event that breaks the layout or the...
Read more >
68622 - Images randomly not displayed - chromium - Monorail
I've now demonstrated the following as well: 1. Go to diversiondesigns.com, make the bug happen. 2. Open a new tab ...
Read more >
How to Fix Randomly Disappearing Absolutely-Positioned ...
The problem is caused by an IE bug that hides an absolutely-positioned element when it's coded immediately before or after a floated element...
Read more >
How do I fix this random bug in svelte - Stack Overflow
Every time I try to run the application it gives me this error enter image description here. It's also always on the first...
Read more >
Bug Types (Summary) - Test IO Academy
When a content or a visual problem occurs repetitively, it may only be submitted once, even though each occurrence may have a different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found