appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

Feature: Search for an inner element by an image #1891

Open wazzeps opened 1 year ago

wazzeps commented 1 year ago

Description

Implement search for an inner element by an image.

Environment

Details

Currently, searching for an element by image works for a driver object. Searching for an element using the root element object results in the error.

org.openqa.selenium.InvalidSelectorException: Locator Strategy '-image' is not supported for this session

Code To Reproduce Issue

public class MobileIcon extends Widget {

    protected MobileIcon(WebElement element) {
        super(element);
    }

    public Rectangle getRect() {
        return findElement(AppiumBy.image(imageRefB64)).getRect();
    }
}
mykola-mokhnach commented 1 year ago

This feature has been recently merged and is available now in the master branch of the server.

wazzeps commented 1 year ago

@mykola-mokhnach, when can we expect the feature to be released?

mykola-mokhnach commented 1 year ago

I believe it is available in the most recent server/plugin releases

wazzeps commented 1 year ago

I'd like to test it but now I'm getting an error when start the server

[debug] [Appium] Error: Cannot find module '@appium/support' [debug] [Appium] Require stack: [debug] [Appium] - /home/wazzeps/.appium/node_modules/@appium/images-plugin/build/lib/constants.js [debug] [Appium] - /home/wazzeps/.appium/node_modules/@appium/images-plugin/build/lib/compare.js [debug] [Appium] - /home/wazzeps/.appium/node_modules/@appium/images-plugin/build/lib/plugin.js [debug] [Appium] - /home/wazzeps/.appium/node_modules/@appium/images-plugin/index.js [debug] [Appium] - /home/wazzeps/.nvm/versions/node/v19.8.1/lib/node_modules/appium/build/lib/extension/extension-config.js [debug] [Appium] - /home/wazzeps/.nvm/versions/node/v19.8.1/lib/node_modules/appium/build/lib/cli/extension-command.js [debug] [Appium] - /home/wazzeps/.nvm/versions/node/v19.8.1/lib/node_modules/appium/build/lib/cli/driver-command.js [debug] [Appium] - /home/wazzeps/.nvm/versions/node/v19.8.1/lib/node_modules/appium/build/lib/cli/extension.js [debug] [Appium] - /home/wazzeps/.nvm/versions/node/v19.8.1/lib/node_modules/appium/build/lib/main.js [debug] [Appium] - /home/wazzeps/.nvm/versions/node/v19.8.1/lib/node_modules/appium/index.js [debug] [Appium] at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1090:15) [debug] [Appium] at Function.Module._load (node:internal/modules/cjs/loader:934:27) [debug] [Appium] at Module.require (node:internal/modules/cjs/loader:1157:19) [debug] [Appium] at require (node:internal/modules/helpers:119:18) [debug] [Appium] at Object. (/home/wazzeps/.appium/node_modules/@appium/images-plugin/lib/constants.js:1:1) [debug] [Appium] at Module._compile (node:internal/modules/cjs/loader:1275:14) [debug] [Appium] at Object.Module._extensions..js (node:internal/modules/cjs/loader:1329:10) [debug] [Appium] at Module.load (node:internal/modules/cjs/loader:1133:32) [debug] [Appium] at Function.Module._load (node:internal/modules/cjs/loader:972:12) [debug] [Appium] at Module.require (node:internal/modules/cjs/loader:1157:19) [debug] [Appium] at require (node:internal/modules/helpers:119:18) [debug] [Appium] at Object. (/home/wazzeps/.appium/node_modules/@appium/images-plugin/lib/compare.js:4:1) [debug] [Appium] at Module._compile (node:internal/modules/cjs/loader:1275:14) [debug] [Appium] at Object.Module._extensions..js (node:internal/modules/cjs/loader:1329:10) [debug] [Appium] at Module.load (node:internal/modules/cjs/loader:1133:32) [debug] [Appium] at Function.Module._load (node:internal/modules/cjs/loader:972:12) [debug] [Appium] at Module.require (node:internal/modules/cjs/loader:1157:19) [debug] [Appium] at require (node:internal/modules/helpers:119:18) [debug] [Appium] at Object. (/home/wazzeps/.appium/node_modules/@appium/images-plugin/lib/plugin.js:6:1) [debug] [Appium] at Module._compile (node:internal/modules/cjs/loader:1275:14) [debug] [Appium] at Object.Module._extensions..js (node:internal/modules/cjs/loader:1329:10) [debug] [Appium] at Module.load (node:internal/modules/cjs/loader:1133:32)

appium 2.0.0-beta.67 images@2.1.0

Could I have missed something?

mykola-mokhnach commented 1 year ago

I've created a patch to address that in the above PR

mykola-mokhnach commented 1 year ago

the patch is now included to the recent server version

YekaterinaRudakova commented 1 year ago

It still doesn't work. The error is org.openqa.selenium.InvalidSelectorException: Locator Strategy '-image' is not supported for this session. I have tried this: getWrappedElement().findElement(AppiumBy.image(imageSelector))

appium 2.0.0-beta.71 images@2.1.1 xcuitest@4.29.5

wazzeps commented 1 year ago

@mykola-mokhnach could you continue working on the feature?

MikitaKarbanovich commented 9 months ago

Hi. I faced with the same error when trying to find element inside other element using image locator strategy. Do you have some advice how to fix it? I use the latest Appium 2.0.1

MikitaKarbanovich commented 9 months ago

@mykola-mokhnach Hi. Could you clarify was it fixed in Appium 2.0.1? Because I see you made some fix steps, but other people and I still have the error when try to find element by image inside other element. Actually I use C# client, but it seems the Appium server issue, not a client.