Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Appium image locator strategy fails for the simplest images. #6097

Closed
Rup1 opened this issue Nov 12, 2020 · 3 comments
Closed

Using Appium image locator strategy fails for the simplest images. #6097

Rup1 opened this issue Nov 12, 2020 · 3 comments
Assignees
Labels
Needs Investigation Issues that require more information on the problem.

Comments

@Rup1
Copy link

Rup1 commented Nov 12, 2020

Environment (please complete the following information):

  • WebdriverIO version: 6.7.3
  • Mode: Standalone
  • Node.js version: 10.x & 12.18.2 (using NVM)
  • NPM version: 6.14.5
  • Browser name and version: N/A
  • Platform name and version: MacOS Catalina 10.15.7
  • Additional wdio packages used (if applicable): "@wdio/appium-service": "^6.7.3", "@wdio/cli": "^6.7.4"

Config of WebdriverIO

const caps = {
    platformName: 'Mac',
    deviceName: "Mac",
    app: "Calculator"
};

const driver = await wdio.remote({
    protocol: "http",
    host: "localhost",
    port: 4723,
    path: "/wd/hub",
    capabilities: caps
  });

Describe the bug
Hard to tell if this is an Appium or wdio issue. Wdio is unable to find the number "1" on macos calculator using an image file, returns 'no such element' error even though element is on the screen and represents a very basic image:

image

calculator:
image

I've tried a bunch of different images, and initially tried on ios. Never works, and I havent' found any working examples online.

To Reproduce
clone the following repository, run npm i and then run node macOsCalculator.
You need to have opencv4nodejs installed on your machine for image search to work.

https://github.com/Rup1/appium-findbyimage

Expected behavior
I expect wdio to easily find the simple image and click the element.

Log
Appium log:
https://gist.github.com/Rup1/2e25a51b26483beb894351cddebeb6d8

@christian-bromann christian-bromann added the Needs Investigation Issues that require more information on the problem. label Nov 12, 2020
@wswebcreation
Copy link
Member

Hi @Rup1

I've tested it and it works on my machine (typical reaction 😆 )

TL:DR

The image that you use can not be matched because the screenshot that is being used to find the image has automatically been resized by Appium.
This means you can't find an element that has for example original dimensions of 100x50 on a screenshot where it has been resized to 50x25.

This can be solved by updating the Appium server with the settings API, see here

Detailed explanation

What happens with Appium is the following:

  1. It receives the base64 image from WebdriverIO
  2. Internally it will trigger a take screenshot of the complete screen that will be used to find your provided image
  3. Before it will compare the image it will determine the original screenshot size and the screen dimensions. This could result in a bigger screenshot in comparison to the screen due to a higher DPR (take retina screens or the screenshot of an iPhone versus the CSS size of the iOS screen, the DPR will be bigger than 1 then). If there is a diff, it will automatically resize the screenshot to the screensize dimensions. This is needed to determine the coordinates on the screen that will be used to tap on
  4. Then it will use the provided image selector to search on the resized screenshot
  5. If it was found the clicking magic will happen, otherwise it will fail

If you created an element screenshot based on the original screenshot where the DPR was bigger than 1 and you compare that with the resized screenshot by Appium it will never find it.

This is from my Appium logs

###############################################################
# Find element, step 1
###############################################################
[HTTP] {"using":"-image","value":"iVBORw0KGgoAAAANSUhEUgAAANIAAAC7CAIAAACfAFeHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAA0qADAAQAAAABAAAAuwAAAAAAVOGuAAAAHGlET1QAAAACAAAAAAAAAF4AAAAoAAAAXgAAAF0AAFP4aN1WLQAAQABJREFUeAHsvQeYXNV5/z8SxSX2L81OfjEg7e70PjtbtCqogASSEBLFmF4N2BShgsAYXOI4Tmwn/qU7CSa26SAEmF6E2mpX23vvvaqstvc9/8/73llJjkukPM//ebC8o6O7d+7cuXPOe77n7eccm+3/99e5tnnn2s6Zbzt3vm3+fNu8+TabdeU82znn8dE827mfsNko51CTeTbb/E/b5n/Kdt75tvM+wbfm2875A9s5n7XZOH7CNp+b5Wlclk/mzTvvXL5AmaeFJ1C4dKJYV+Sx8mQp1unH52jVimpZVfq19bdaF2spTaa50FOIaVFv/meESkIiiCL0OR/qfdI2H4J9mufyTKWwUEk+hexKee0IfQ5dw1f5SCh3VrwEKBQhCA2LQUSvcFExZJvPHecrMIT288+TAl3OA5TcL9/nU5Co9D533vzzbefy0SyStN/mzZMf4Jp227zz5skzKVCaiydvpgqz7z4mJ1L92arw16o2R23CvNgn8xhhtEzHjXU/x3O55XzIC1l0mMp35QXRIB0EhIzzhFA8BALqpxbs+Ib8jqCQwv1W7wi1Ys+wnvQ7fDxH+ZBFWav9n1QqSIOt1jJqrZfSeN4nhFInBr18+/xzbJ9U4MrgPu/c+efNt77CA85TKkO4+Yzy2Y7RflRy8sTYG4vCQuSP2etExeTEqu882hMDXAxqNE2KtEmarHdCBEgBQZSBzRcSQaj5MZYFLXja/PMBX+yxQgoREVr4xGazOkJ+UygvvJDvy21nwYuRJY...
[debug] [W3C (b8457935)] Calling AppiumDriver.findElement() with args: ["-image","iVBORw0KGgoAAAANSUhEUgAAANIAAAC7CAIAAACfAFeHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAA0qADAAQAAAABAAAAuwAAAAAAVOGuAAAAHGlET1QAAAACAAAAAAAAAF4AAAAoAAAAXgAAAF0AAFP4aN1WLQAAQABJREFUeAHsvQeYXNV5/z8SxSX2L81OfjEg7e70PjtbtCqogASSEBLFmF4N2BShgsAYXOI4Tmwn/qU7CSa26SAEmF6E2mpX23vvvaqstvc9/8/73llJjkukPM//ebC8o6O7d+7cuXPOe77n7eccm+3/99e5tnnn2s6Zbzt3vm3+fNu8+TabdeU82znn8dE827mfsNko51CTeTbb/E/b5n/Kdt75tvM+wbfm2875A9s5n7XZOH7CNp+b5Wlclk/mzTvvXL5AmaeFJ1C4dKJYV+Sx8mQp1unH52jVimpZVfq19bdaF2spTaa50FOIaVFv/meESkIiiCL0OR/qfdI2H4J9mufyTKWwUEk+hexKee0IfQ5dw1f5SCh3VrwEKBQhCA2LQUSvcFExZJvPHecrMIT288+TAl3OA5TcL9/nU5Co9D533vzzbefy0SyStN/mzZMf4Jp227zz5skzKVCaiydvpgqz7z4mJ1L92arw16o2R23CvNgn8xhhtEzHjXU/x3O55XzIC1l0mMp35QXRIB0EhIzzhFA8BALqpxbs+Ib8jqCQwv1W7wi1Ys+wnvQ7fDxH+ZBFWav9n1QqSIOt1jJqrZfSeN4nhFInBr18+/xzbJ9U4MrgPu/c+efNt77CA85TKkO4+Yzy2Y7RflRy8sTYG4vCQuSP2etExeTEqu882hMDXAxqNE2KtEmarHdCBEgBQZSBzRcSQaj5MZYFLXja/PMBX+yxQgoREVr4xGazOkJ+UygvvJDvy21nwYuRJY2RhslQoqmIg09bpD...
[debug] [XCUITest] Executing command 'findElement'
[BaseDriver] Finding image element with match threshold 0.4

###############################################################
# Get screensize which is used for step 3
###############################################################
[debug] [WD Proxy] Proxying [GET /window/size] to [GET http://127.0.0.1:8100/session/D5EE27B4-EF6C-4D65-9AA2-AA04610EB874/window/size] with no body
[debug] [WD Proxy] Got response with status 200: {"value":{"width":414,"height":896},"sessionId":"D5EE27B4-EF6C-4D65-9AA2-AA04610EB874"}
[debug] [BaseDriver] Waiting up to 0 ms for condition

###############################################################
# Take the screenshot for step 2
###############################################################
[debug] [XCUITest] Taking screenshot with WDA
[debug] [WD Proxy] Matched '/screenshot' to command name 'getScreenshot'
[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/D5EE27B4-EF6C-4D65-9AA2-AA04610EB874/screenshot] with no body
[debug] [WD Proxy] Got response with status 200: {"value":"iVBORw0KGgoAAAANSUhEUgAAAzwAAAcACAIAAACaY9F8AAAAAXNSR0IArs4c6QAA\r\nAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKAC\r\nAAQAAAABAAADPKADAAQAAAABAAAHAAAAAAAYjVEBAAAAHGlET1QAAAACAAAAAAAA\r\nA4AAAAAoAAADgAAAA4AAB0ZYF8v/LwAAQABJREFUeAHsnQl8VcXZ/xMWAZEdErLc\r\ne5MgStW6W5e21qqtW12QNWQPuFRbW7XWrm9r37b6ahe1Vq27IDtZSNhCQhb2sC9h\r\nR+VPEVBk3zfv/zvnuRkO9yYhQgIJPOczjnPmzJkz8z2TOz+eWU5YmB5KQAkoASWg\r\nBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJ\r\nKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQ\r\nAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAE\r\nlIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAko\r\nASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElAC\r\nSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASU\r\ngBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgB\r\nJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJK\r\nQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASW...

###############################################################
# Verifying the screenshot size vs the screen size, for step 3
###############################################################
[BaseDriver] Verifying screenshot size and aspect ratio
[BaseDriver] Screenshot aspect ratio '0.46205357142857145' (828x1792) matched screen aspect ratio '0.46205357142857145' (414x896)

###############################################################
# The find element based on the image selector, step 4
###############################################################
[BaseDriver] Scaling screenshot from 828x1792 to match screen at 414x896
[debug] [W3C (b8457935)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[debug] [W3C (b8457935)]     at XCUITestDriver.findByImage (/Users/wimselles/.nvm/versions/node/v12.19.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/node_modules/appium-base-driver/lib/basedriver/commands/find.js:280:11)
[HTTP] <-- POST /session/b8457935-e0e7-4cd7-80c0-f5747e98d016/element 404 1770 ms - 455

Now think what will happen when the original screenshot is resized from 828x1792 to 414x896, then you will never be able to find the element

Original screenshot
screen-iphone_11-ios-13 7
Element screenshot
swaglabs-iphone_11-ios-13 7
Resized screenshot
screen-half-iphone_11-ios-13 7

But when you adjust the server settings with this, before you run the image selection it will work, see also the new logs with explained steps

        browser.updateSettings({
            // See https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/image-elements.md#related-settings
            fixImageTemplateScale: true,
        });
###############################################################
# Find element, step 1
###############################################################
[debug] [W3C (54dcc529)] Calling AppiumDriver.findElement() with args: ["-image","iVBORw0KGgoAAAANSUhEUgAAANIAAAC7CAIAAACfAFeHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAA0qADAAQAAAABAAAAuwAAAAAAVOGuAAAAHGlET1QAAAACAAAAAAAAAF4AAAAoAAAAXgAAAF0AAFP4aN1WLQAAQABJREFUeAHsvQeYXNV5/z8SxSX2L81OfjEg7e70PjtbtCqogASSEBLFmF4N2BShgsAYXOI4Tmwn/qU7CSa26SAEmF6E2mpX23vvvaqstvc9/8/73llJjkukPM//ebC8o6O7d+7cuXPOe77n7eccm+3/99e5tnnn2s6Zbzt3vm3+fNu8+TabdeU82znn8dE827mfsNko51CTeTbb/E/b5n/Kdt75tvM+wbfm2875A9s5n7XZOH7CNp+b5Wlclk/mzTvvXL5AmaeFJ1C4dKJYV+Sx8mQp1unH52jVimpZVfq19bdaF2spTaa50FOIaVFv/meESkIiiCL0OR/qfdI2H4J9mufyTKWwUEk+hexKee0IfQ5dw1f5SCh3VrwEKBQhCA2LQUSvcFExZJvPHecrMIT288+TAl3OA5TcL9/nU5Co9D533vzzbefy0SyStN/mzZMf4Jp227zz5skzKVCaiydvpgqz7z4mJ1L92arw16o2R23CvNgn8xhhtEzHjXU/x3O55XzIC1l0mMp35QXRIB0EhIzzhFA8BALqpxbs+Ib8jqCQwv1W7wi1Ys+wnvQ7fDxH+ZBFWav9n1QqSIOt1jJqrZfSeN4nhFInBr18+/xzbJ9U4MrgPu/c+efNt77CA85TKkO4+Yzy2Y7RflRy8sTYG4vCQuSP2etExeTEqu882hMDXAxqNE2KtEmarHdCBEgBQZSBzRcSQaj5MZYFLXja/PMBX+yxQgoREVr4xGazOkJ+UygvvJDvy21nwYuRJY2RhslQoqmIg09bpD...
[debug] [XCUITest] Executing command 'findElement'
[BaseDriver] Finding image element with match threshold 0.4

###############################################################
# Get screensize which is used for step 3
###############################################################
[debug] [WD Proxy] Proxying [GET /window/size] to [GET http://127.0.0.1:8100/session/BB0C2133-241B-4FA5-BC19-25653E7CC95F/window/size] with no body
[debug] [WD Proxy] Got response with status 200: {"value":{"width":414,"height":896},"sessionId":"BB0C2133-241B-4FA5-BC19-25653E7CC95F"}
[debug] [BaseDriver] Waiting up to 0 ms for condition

###############################################################
# Take the screenshot for step 2
###############################################################
[debug] [XCUITest] Taking screenshot with WDA
[debug] [WD Proxy] Matched '/screenshot' to command name 'getScreenshot'
[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/BB0C2133-241B-4FA5-BC19-25653E7CC95F/screenshot] with no body
[debug] [WD Proxy] Got response with status 200: {"value":"iVBORw0KGgoAAAANSUhEUgAAAzwAAAcACAIAAACaY9F8AAAAAXNSR0IArs4c6QAA\r\nAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKAC\r\nAAQAAAABAAADPKADAAQAAAABAAAHAAAAAAAYjVEBAAAAHGlET1QAAAACAAAAAAAA\r\nA4AAAAAoAAADgAAAA4AAB0WYp4JuXAAAQABJREFUeAHsnQd8VtXdx5MAAiobsp/n\r\nSYJb67ZW21qr1tU6kE0mAUe1WketXe/b2ulrl7bWWrcgmwwSVkjIYIcNCUscFFmK\r\n7L183u+5/yeHy/MkIUICSfjfz/F47rnnnnvO954858f/jBsWpocSUAJKQAkoASWg\r\nBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJ\r\nKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQ\r\nAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAE\r\nlIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAko\r\nASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElAC\r\nSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASU\r\ngBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgB\r\nJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJK\r\nQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASW...

###############################################################
# Verifying the screenshot size vs the screen size, for step 3
###############################################################
[BaseDriver] Verifying screenshot size and aspect ratio
[BaseDriver] Screenshot aspect ratio '0.46205357142857145' (828x1792) matched screen aspect ratio '0.46205357142857145' (414x896)
[BaseDriver] Scaling screenshot from 828x1792 to match screen at 414x896

###############################################################
# The find element based on the image selector, step 4
###############################################################
[BaseDriver] Scaling template image from 210x187 to 105x93.5
[BaseDriver] The ratio is 0.5 and 0.5
[BaseDriver] Image template matched: {"x":203,"y":188,"width":105,"height":94}
[BaseDriver] Matched base64 data: iVBORw0KGgoAAAANSUhEUgAAAZ4AAAOACAIAAACFXYKaAAAgAElEQVR4AezBC5yddX0u+uf5/d91mclckklIMplJCAQwEkBFsaKlBFHCaVCqokm8oHLUCoiX7qqnFpBq6mZbi7WfSkSsiBIvgFAPaNhbFIHadnONIUQuAXKZ3Ce3ua/1vv/fsydL5zQckpLRWRLH9/sl...

###############################################################
# Because of the settings update we now also tell
# Appium to resize the provided image and it can do all
# clicking magic, see step 5
###############################################################
[debug] [W3C (54dcc529)] Responding to client with driver.findElement() result: {"ELEMENT":"appium-image-element-6adde0c8-5cef-4c88-b80b-6687875b2f29","element-6066-11e4-a52e-4f735466cecf":"appium-image-element-6adde0c8-5cef-4c88-b80b-6687875b2f29"}
[HTTP] <-- POST /session/54dcc529-1ddf-48e4-bbb4-e3089e4e9366/element 200 427 ms - 179
[HTTP]
[HTTP] --> POST /session/54dcc529-1ddf-48e4-bbb4-e3089e4e9366/element/appium-image-element-6adde0c8-5cef-4c88-b80b-6687875b2f29/click
[HTTP] {}
[debug] [W3C (54dcc529)] Calling AppiumDriver.click() with args: ["appium-image-element-6adde0c8-5cef-4c88-b80b-6687875b2f29","54dcc529-1ddf-48e4-bbb4-e3089e4e9366"]
[debug] [XCUITest] Executing command 'click'
[BaseDriver] Checking image element for staleness before clicking
[BaseDriver] Finding image element with match threshold 0.4
[debug] [WD Proxy] Proxying [GET /window/size] to [GET http://127.0.0.1:8100/session/BB0C2133-241B-4FA5-BC19-25653E7CC95F/window/size] with no body
[debug] [WD Proxy] Got response with status 200: {"value":{"width":414,"height":896},"sessionId":"BB0C2133-241B-4FA5-BC19-25653E7CC95F"}
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [XCUITest] Taking screenshot with WDA
[debug] [WD Proxy] Matched '/screenshot' to command name 'getScreenshot'
[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/BB0C2133-241B-4FA5-BC19-25653E7CC95F/screenshot] with no body
[debug] [WD Proxy] Got response with status 200: {"value":"iVBORw0KGgoAAAANSUhEUgAAAzwAAAcACAIAAACaY9F8AAAAAXNSR0IArs4c6QAA\r\nAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKAC\r\nAAQAAAABAAADPKADAAQAAAABAAAHAAAAAAAYjVEBAAAAHGlET1QAAAACAAAAAAAA\r\nA4AAAAAoAAADgAAAA4AAB0WYp4JuXAAAQABJREFUeAHsnQd8VtXdx5MAAiobsp/n\r\nSYJb67ZW21qr1tU6kE0mAUe1WketXe/b2ulrl7bWWrcgmwwSVkjIYIcNCUscFFmK\r\n7L183u+5/yeHy/MkIUICSfjfz/F47rnnnnvO954858f/jBsWpocSUAJKQAkoASWg\r\nBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJ\r\nKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQ\r\nAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAE\r\nlIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAko\r\nASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElAC\r\nSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASU\r\ngBJQAkpACSgBJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgB\r\nJaAElIASUAJKQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJK\r\nQAkoASWgBJSAElACSkAJKAEloASUgBJQAkpACSgBJaAElIASUAJKQAkoASW...
[BaseDriver] Verifying screenshot size and aspect ratio
[BaseDriver] Screenshot aspect ratio '0.46205357142857145' (828x1792) matched screen aspect ratio '0.46205357142857145' (414x896)
[BaseDriver] Scaling screenshot from 828x1792 to match screen at 414x896
[BaseDriver] Scaling template image from 105x94 to 52.5x47
[BaseDriver] The ratio is 0.5 and 0.5
[BaseDriver] Image template matched: {"x":73,"y":539,"width":53,"height":47}
[BaseDriver] Matched base64 data: iVBORw0KGgoAAAANSUhEUgAAAZ4AAAOACAIAAACFXYKaAAAgAElEQVR4AezBC5yddX0u+uf5/d91mclckklIMplJCAQwEkBFsaKlBFHCaVCqokm8oHLUCoiX7qqnFpBq6mZbi7WfSkSsiBIvgFAPaNhbFIHadnONIUQuAXKZ3Ce3ua/1vv/fsydL5zQckpLRWRLH9/sl...
[BaseDriver] When trying to click on an image element, the image changed position from where it was originally found. It is now at {"x":73,"y":539,"width":53,"height":47} and was originally at {"x":203,"y":188,"width":105,"height":94}.
[BaseDriver] Click will take place at original coordinates. If you would like Appium to automatically click the new coordinates, set the 'autoUpdateImageElementPosition' setting to true
[BaseDriver] Will tap on image element at coordinate [255.5, 235]
[BaseDriver] Will tap using W3C actions
[debug] [XCUITest] Received the following W3C actions: [
[debug] [XCUITest]   {
[debug] [XCUITest]     "type": "pointer",
[debug] [XCUITest]     "id": "mouse",
[debug] [XCUITest]     "parameters": {
[debug] [XCUITest]       "pointerType": "touch"
[debug] [XCUITest]     },
[debug] [XCUITest]     "actions": [
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pointerMove",
[debug] [XCUITest]         "x": 255.5,
[debug] [XCUITest]         "y": 235,
[debug] [XCUITest]         "duration": 0
[debug] [XCUITest]       },
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pointerDown",
[debug] [XCUITest]         "button": 0
[debug] [XCUITest]       },
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pause",
[debug] [XCUITest]         "duration": 125
[debug] [XCUITest]       },
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pointerUp",
[debug] [XCUITest]         "button": 0
[debug] [XCUITest]       }
[debug] [XCUITest]     ]
[debug] [XCUITest]   }
[debug] [XCUITest] ]
[debug] [XCUITest] Preprocessed actions: [
[debug] [XCUITest]   {
[debug] [XCUITest]     "type": "pointer",
[debug] [XCUITest]     "id": "mouse",
[debug] [XCUITest]     "parameters": {
[debug] [XCUITest]       "pointerType": "touch"
[debug] [XCUITest]     },
[debug] [XCUITest]     "actions": [
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pointerMove",
[debug] [XCUITest]         "x": 255.5,
[debug] [XCUITest]         "y": 235,
[debug] [XCUITest]         "duration": 0
[debug] [XCUITest]       },
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pointerDown",
[debug] [XCUITest]         "button": 0
[debug] [XCUITest]       },
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pause",
[debug] [XCUITest]         "duration": 125
[debug] [XCUITest]       },
[debug] [XCUITest]       {
[debug] [XCUITest]         "type": "pointerUp",
[debug] [XCUITest]         "button": 0
[debug] [XCUITest]       }
[debug] [XCUITest]     ]
[debug] [XCUITest]   }
[debug] [XCUITest] ]
[debug] [WD Proxy] Matched '/actions' to command name 'performActions'
[debug] [WD Proxy] Proxying [POST /actions] to [POST http://127.0.0.1:8100/session/BB0C2133-241B-4FA5-BC19-25653E7CC95F/actions] with body: {"actions":[{"type":"pointer","id":"mouse","parameters":{"pointerType":"touch"},"actions":[{"type":"pointerMove","x":255.5,"y":235,"duration":0},{"type":"pointerDown","button":0},{"type":"pause","duration":125},{"type":"pointerUp","button":0}]}]}
[debug] [WD Proxy] Got response with status 200: {"value":null,"sessionId":"BB0C2133-241B-4FA5-BC19-25653E7CC95F"}
[debug] [W3C (54dcc529)] Responding to client with driver.click() result: null
[HTTP] <-- POST /session/54dcc529-1ddf-48e4-bbb4-e3089e4e9366/element/appium-image-element-6adde0c8-5cef-4c88-b80b-6687875b2f29/click 200 649 ms - 14

I've tested it with this script on my local machine

describe('Find by Image', () => {
    it('should be able to find and element and click on it', () => {
        browser.updateSettings({
            // See https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/image-elements.md#related-settings
            fixImageTemplateScale: true,
        });

        // For demo purpose
        browser.pause(5000);

        // Click on the image
        $('image.png').click();

        // For demo purpose
        browser.pause(5000);
    });
});

@Rup1
Copy link
Author

Rup1 commented Nov 14, 2020

@wswebcreation Wow that was quick! Really great explanation thank you so much for the details. I was able to update accordingly and get it to work. It would help many others if this explanation were included in the docs, which currently lack practical javascript examples.

Cheers

@wswebcreation
Copy link
Member

Hi @Rup1

Great that it works, we already updated the docs (#6104) which will be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation Issues that require more information on the problem.
Projects
None yet
Development

No branches or pull requests

3 participants