How to find a image

My enviroment:
Appium 1.22.3
Android 11

I need how to use “driver.find_element(AppiumBy.IMAGE, ‘’”) or driver.find_element_by_image("") to find an image.

To obtain the value in base 64 I used this: encoded = base64.b64encoded(open(“Captura.png”, “rb”).read())

try links:
https://appiumpro.com/editions/32-finding-elements-by-image-part-1
https://appiumpro.com/editions/33-finding-elements-by-image-part-2

Hello,

I do this:

First, I get the value of base64EncodedImageFile like this:

encoded = base64.b64encode(open(“C:/Users/NMX-Celia/OneDrive/Escritorio/APPIUM/Captura.png”, “rb”).read())
print(encoded)

The image I want to find is:

Captura.PNG

And what I see on the screen is this:

image.png

Then, I try this:

el = driver.find_element_by_image(encoded)

el.click()

And I see this error:

Traceback (most recent call last):
File “C:\Users\NMX-Celia\PycharmProjects\Appiumconpython\ClashRoyale.py”, line 33, in
el = driver.find_element_by_image(‘encoded’)
File “C:\Users\NMX-Celia\PycharmProjects\Appiumconpython\venv\lib\site-packages\appium\webdriver\extensions\search_context\mobile.py”, line 87, in find_element_by_image
with open(img_path, ‘rb’) as i_file:
FileNotFoundError: [Errno 2] No such file or directory: ‘…xxxx.encoded’

What is the problem?

How you create image that need to be found?

Last time I did this I made image by capturing needed image with Appium. Thus Appium itself making image that need to be found later. This eliminates problems when we capture image with any imageEditor amd saving in a way that cam harm it (e.g. original pallet replaced, colors changed and so on).

Did you try to change driver.setSetting(Setting.IMAGE_MATCH_THRESHOLD, 0.2); ?

First, I get the screenshot using the computer but then I found this command: drvier.get_screenshot_as_base64(), but I need to find the size of the rectangle, how can I do that?

Thank you!!

// java

// get screenshot of some element as base64 string
WebElement el = driver.findElement(AppiumBy.id("myID"));
String base64Image = el.getScreenshotAs(OutputType.BASE64);

// get screenshot of whole screen as file
File file = driver.getScreenshotAs(OutputType.FILE);

-> http://appium.io/docs/en/commands/session/screenshot/

I solved the problem for screenshot with de PIL’s library. On the other hand, when I launch the following command:

el = driver.find_element(AppiumBy.IMAGE, ‘battle.png’)

I get this error:

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\NMX-Celia\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\webdriver.py”, line 414, in find_element
return self.execute(RemoteCommand.FIND_ELEMENT, {‘using’: by, ‘value’: value})[‘value’]
File “C:\Users\NMX-Celia\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 425, in execute
self.error_handler.check_response(response)
File “C:\Users\NMX-Celia\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\errorhandler.py”, line 30, in check_response
raise wde
File “C:\Users\NMX-Celia\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\errorhandler.py”, line 26, in check_response
super().check_response(response)
File “C:\Users\NMX-Celia\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: ‘opencv4nodejs’ module is required to use OpenCV features. Please install it first (‘npm i -g opencv4nodejs’) and restart Appium. Read GitHub - justadudewhohacks/opencv4nodejs: Nodejs bindings to OpenCV 3 and OpenCV 4 for more details on this topic.
Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: ‘opencv4nodejs’ module is required to use OpenCV features. Please install it first (‘npm i -g opencv4nodejs’) and restart Appium. Read GitHub - justadudewhohacks/opencv4nodejs: Nodejs bindings to OpenCV 3 and OpenCV 4 for more details on this topic.
at getResponseForW3CError (C:\Users\NMX-Celia\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
at asyncHandler (C:\Users\NMX-Celia\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:380:37)

I have followed these steps: opencv4nodejs - npm
But I keep getting the same error, do you know what it could be?

did you try this one?

Yes, when I launch the command I see this:

opencv4node package is not maintained and is in broken state. Please follow https://github.com/appium/appium/issues/17041#issuecomment-1147737469

will add a bit more links migrate to appium 2.0 and images: