appium / java-client

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

Appium 2.0: Not able to click on image locator #2180

Closed dipakkumar1225 closed 2 months ago

dipakkumar1225 commented 3 months ago

Description

Not able to click on image locator

installed driver list

installed plugin list

Environment

Details

Please provide more details, if necessary.

Code To Reproduce Issue [ Good To Have ]

File resourcePath = new File("D:\\Workspace\\IPPB\\psp\\paymentservicesprovider\\src\\main\\resources\\elements\\BackArrow.png");
try {
    String abc = Base64.getEncoder().encodeToString(Files.readAllBytes(resourcePath.toPath()));
    WebDriverWait wait = new WebDriverWait(getAppiumDriver(), Duration.ofSeconds(10));
    By sunriseImage = AppiumBy.image(abc);
    wait.until(ExpectedConditions.presenceOfElementLocated(sunriseImage)).click();
} catch (IOException e) {
    throw new RuntimeException(e);
}

Exception Stacktraces

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: AppiumBy.image: iVBORw0KGgoAAAANSUhEUgAAADQAAAAuCAYAAABnNToWAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAKkSURBVGiB3Zq/z/FQFMevRkRIExIDCYPFwiIGizSxMom/wEpja2wiYZEYTQT/gJHJZGOxsDAYLF3E0EhEhPNOz/vDw72Htnqf95PcrUm/n7S3zjmXDQCA6GS1WpH9fk+9JpFIEFEU9d6KDehkuVyCw+EAQsjTlUql4Hq96r0VCl1Cp9MJIpEIVcbj8YCqqkblZaJLqFgsUmUIITAej43KiuJtodFoxJQplUpGZkXxlpCqquD1eqky0WgUzuez0XmZvCx0u91AkiSqjNPphM1mY0ZeJi8LNZtN5qvW7XbNyIriJaHFYgF2u50qk8vlzMqKAi10PB4hHA5TZYLBIGiaZmZeJmihQqFAlREEAebzuZlZUaCEhsMhc980Gg2zs6JgCu12OxBFkVna3G63T+RlQhW6Xq+QTCa5Km1YUIVqtRp3pQ2Lp0Kz2QwEQaDKlMvlT2ZF8VBI0zQIhUJcljYsHgrl83mqjMvlsqy0YfFNaDAYMPdNr9ezIiuKf4S22y243W6uSxsWv4UulwvE43Hm0+F+fQlVKhXrwxglNJ1OwWazWR/GKKFAIGB9EIOWQAghmUyG/DcA4HqdH7O+PgqYbvQnLBvAn1Fwq9UiiqJQnich6XSaSJJEvcZS/v5Rwkx0eGsX7vlW+qiqCj6fjyrFU0N3z8PidDKZMN/Ver3+6awonvZDsizTv/ecDEXueSp0Pp8hFotRpXgYW91DbcHX6zU4nU6qFG/VN3Pq0263mfup0+l8IisK1Fwum81Shawczt+DEjocDuD3+6lSvMwY0KNgTIshy7KZWVG8dPqgKApzP1k9p3tJCNOmW10avXzghRmkWFkavXXG2u/3uS2N3j4FZw0jrSqN3hbCjIutKI10/fECM9D/dGmk+78+1WqVq9LoF+nwlSoJcyzAAAAAAElFTkSuQmCC (tried for 10 second(s) with 500 milliseconds interval)
   at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:84)
   at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
   at screens.prelogin.LanguageSelection.clickOnHelpIcon(LanguageSelection.java:89)
   at stepDefinitions.prelogin.splash.LanguageSelectionDefinition.clickOnHelpIconPresentOnTopRightOfTheScreen(LanguageSelectionDefinition.java:62)
   at ✽.click on help icon present on top-right of the screen(classpath:features/02_LanguageSelection.feature:70)
Caused by: org.openqa.selenium.NoSuchElementException: Time out after waiting for element iVBORw0KGgoAAAANSUhEUgAAADQAAAAuCAYAAABnNToWAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAKkSURBVGiB3Zq/z/FQFMevRkRIExIDCYPFwiIGizSxMom/wEpja2wiYZEYTQT/gJHJZGOxsDAYLF3E0EhEhPNOz/vDw72Htnqf95PcrUm/n7S3zjmXDQCA6GS1WpH9fk+9JpFIEFEU9d6KDehkuVyCw+EAQsjTlUql4Hq96r0VCl1Cp9MJIpEIVcbj8YCqqkblZaJLqFgsUmUIITAej43KiuJtodFoxJQplUpGZkXxlpCqquD1eqky0WgUzuez0XmZvCx0u91AkiSqjNPphM1mY0ZeJi8LNZtN5qvW7XbNyIriJaHFYgF2u50qk8vlzMqKAi10PB4hHA5TZYLBIGiaZmZeJmihQqFAlREEAebzuZlZUaCEhsMhc980Gg2zs6JgCu12OxBFkVna3G63T+RlQhW6Xq+QTCa5Km1YUIVqtRp3pQ2Lp0Kz2QwEQaDKlMvlT2ZF8VBI0zQIhUJcljYsHgrl83mqjMvlsqy0YfFNaDAYMPdNr9ezIiuKf4S22y243W6uSxsWv4UulwvE43Hm0+F+fQlVKhXrwxglNJ1OwWazWR/GKKFAIGB9EIOWQAghmUyG/DcA4HqdH7O+PgqYbvQnLBvAn1Fwq9UiiqJQnich6XSaSJJEvcZS/v5Rwkx0eGsX7vlW+qiqCj6fjyrFU0N3z8PidDKZMN/Ver3+6awonvZDsizTv/ecDEXueSp0Pp8hFotRpXgYW91DbcHX6zU4nU6qFG/VN3Pq0263mfup0+l8IisK1Fwum81Shawczt+DEjocDuD3+6lSvMwY0KNgTIshy7KZWVG8dPqgKApzP1k9p3tJCNOmW10avXzghRmkWFkavXXG2u/3uS2N3j4FZw0jrSqN3hbCjIutKI10/fECM9D/dGmk+78+1WqVq9LoF+nwlSoJcyzAAAAAAElFTkSuQmCC for 55000 ms
For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Build info: version: '4.21.0', revision: '79ed462ef4'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '21.0.3'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [b7aa2b47-1dac-4da1-b468-9a67b71299c5, findElement {value=iVBORw0KGgoAAAANSUhEUgAAADQAAAAuCAYAAABnNToWAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAKkSURBVGiB3Zq/z/FQFMevRkRIExIDCYPFwiIGizSxMom/wEpja2wiYZEYTQT/gJHJZGOxsDAYLF3E0EhEhPNOz/vDw72Htnqf95PcrUm/n7S3zjmXDQCA6GS1WpH9fk+9JpFIEFEU9d6KDehkuVyCw+EAQsjTlUql4Hq96r0VCl1Cp9MJIpEIVcbj8YCqqkblZaJLqFgsUmUIITAej43KiuJtodFoxJQplUpGZkXxlpCqquD1eqky0WgUzuez0XmZvCx0u91AkiSqjNPphM1mY0ZeJi8LNZtN5qvW7XbNyIriJaHFYgF2u50qk8vlzMqKAi10PB4hHA5TZYLBIGiaZmZeJmihQqFAlREEAebzuZlZUaCEhsMhc980Gg2zs6JgCu12OxBFkVna3G63T+RlQhW6Xq+QTCa5Km1YUIVqtRp3pQ2Lp0Kz2QwEQaDKlMvlT2ZF8VBI0zQIhUJcljYsHgrl83mqjMvlsqy0YfFNaDAYMPdNr9ezIiuKf4S22y243W6uSxsWv4UulwvE43Hm0+F+fQlVKhXrwxglNJ1OwWazWR/GKKFAIGB9EIOWQAghmUyG/DcA4HqdH7O+PgqYbvQnLBvAn1Fwq9UiiqJQnich6XSaSJJEvcZS/v5Rwkx0eGsX7vlW+qiqCj6fjyrFU0N3z8PidDKZMN/Ver3+6awonvZDsizTv/ecDEXueSp0Pp8hFotRpXgYW91DbcHX6zU4nU6qFG/VN3Pq0263mfup0+l8IisK1Fwum81Shawczt+DEjocDuD3+6lSvMwY0KNgTIshy7KZWVG8dPqgKApzP1k9p3tJCNOmW10avXzghRmkWFkavXXG2u/3uS2N3j4FZw0jrSqN3hbCjIutKI10/fECM9D/dGmk+78+1WqVq9LoF+nwlSoJcyzAAAAAAElFTkSuQmCC, using=-image}]
Capabilities {appium:app: D:\Workspace\IPPB\psp\payme..., appium:appActivity: com.demo.app.MainActivity, appium:appPackage: com.demo.app, appium:autoGrantPermissions: true, appium:autoLaunch: false, appium:automationName: UIAutomator2, appium:chromedriverPort: 10002, appium:clearDeviceLogsOnStart: true, appium:clearSystemFiles: true, appium:databaseEnabled: false, appium:desired: {app: D:\Workspace\IPPB\psp\payme..., appActivity: com.demo.app.MainActivity, appPackage: com.demo.app, autoGrantPermissions: true, autoLaunch: false, automationName: UIAutomator2, chromedriverPort: 10002, clearDeviceLogsOnStart: true, clearSystemFiles: true, ensureWebviewsHavePages: true, fullReset: false, hideKeyboard: true, ignoreHiddenApiPolicyError: true, newCommandTimeout: 240, noReset: true, platformName: ANDROID, platformVersion: 13, printPageSourceOnFindFailure: true, recreateChromeDriverSessions: true, shouldTerminateApp: true, showChromedriverLog: true, systemPort: 10001, udid: ZD222CJSXB, webviewDevtoolsPort: 10901}, appium:deviceApiLevel: 33, appium:deviceManufacturer: motorola, appium:deviceModel: motorola edge 30, appium:deviceName: ZD222CJSXB, appium:deviceScreenDensity: 400, appium:deviceScreenSize: 1080x2400, appium:deviceUDID: ZD222CJSXB, appium:ensureWebviewsHavePages: true, appium:fullReset: false, appium:hideKeyboard: true, appium:ignoreHiddenApiPolicyError: true, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:newCommandTimeout: 240, appium:noReset: true, appium:pixelRatio: 2.5, appium:platformVersion: 13, appium:printPageSourceOnFindFailure: true, appium:recreateChromeDriverSessions: true, appium:shouldTerminateApp: true, appium:showChromedriverLog: true, appium:statBarHeight: 105, appium:systemPort: 10001, appium:takesScreenshot: true, appium:udid: ZD222CJSXB, appium:viewportRect: {height: 2130, left: 0, top: 105, width: 1080}, appium:warnings: {}, appium:webStorageEnabled: false, appium:webviewDevtoolsPort: 10901, platformName: ANDROID}
Session ID: b7aa2b47-1dac-4da1-b468-9a67b71299c5
   at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
   at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
   at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
   at org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:167)
   at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:138)
   at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50)
   at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:190)
   at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:237)
   at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
   at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:165)
   at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:66)
   at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
   at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:349)
   at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:171)
   at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:168)
   at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:203)
   at screens.prelogin.LanguageSelection.clickOnHelpIcon(LanguageSelection.java:89)
   at stepDefinitions.prelogin.splash.LanguageSelectionDefinition.clickOnHelpIconPresentOnTopRightOfTheScreen(LanguageSelectionDefinition.java:62)
   at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
   at java.base/java.lang.reflect.Method.invoke(Method.java:580)
   at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
   at io.cucumber.java.Invoker.invoke(Invoker.java:24)
   at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
   at io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29)
   at io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66)
   at io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63)
   at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
   at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:81)
   at io.cucumber.core.runner.TestStep.run(TestStep.java:53)
   at io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51)
   at io.cucumber.core.runner.TestCase.run(TestCase.java:84)
   at io.cucumber.core.runner.Runner.runPickle(Runner.java:75)
   at io.cucumber.testng.TestNGCucumberRunner.lambda$runScenario$1(TestNGCucumberRunner.java:132)
   at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:136)
   at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
   at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:136)
   at io.cucumber.testng.TestNGCucumberRunner.runScenario(TestNGCucumberRunner.java:129)
   at io.cucumber.testng.AbstractTestNGCucumberTests.runScenario(AbstractTestNGCucumberTests.java:35)
   at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
   at java.base/java.lang.reflect.Method.invoke(Method.java:580)
   at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:141)
   at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:686)
   at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:230)
   at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:63)
   at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:992)
   at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:203)
   at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:154)
   at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:134)
   at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
   at org.testng.TestRunner.privateRun(TestRunner.java:739)
   at org.testng.TestRunner.run(TestRunner.java:614)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:421)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:413)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:373)
   at org.testng.SuiteRunner.run(SuiteRunner.java:312)
   at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
   at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1274)
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1269)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:1208)
   at org.testng.TestNG.runSuites(TestNG.java:1112)
   at org.testng.TestNG.run(TestNG.java:1079)
   at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:308)
   at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:71)
   at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:113)
   at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
   at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
   at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
   at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

Link To Appium Logs

https://gist.github.com/dipakkumar1225/2997b7c5a1dc7c4bb93c161589eb439f

dipakkumar1225 commented 3 months ago

The element-wait plugin conflicts with the images plugin. After removing the element-wait plugin from the --use-plugins list, the image element is clicked properly.

public class Main {

    private static AppiumDriverLocalService getAppiumDriverService() {
        String strDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMMM_dd_yyyy"));
        String strTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH_mm_ss"));
        var strReportDir = Paths.get(System.getProperty("user.dir"), strDate);

        String logFileName = String.format("Appium_Server_%s.log", strTime);
        File logFile = new File(Paths.get(strReportDir.toString(), logFileName).toString());

        return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                .withIPAddress("127.0.0.1")
                .usingPort(4723)
                .withArgument(() -> "--long-stacktrace")
                .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
                .withArgument(GeneralServerFlag.USE_DRIVERS, "uiautomator2")
                .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell")
                .withArgument(GeneralServerFlag.RELAXED_SECURITY)
                .withArgument(GeneralServerFlag.USE_PLUGINS, "images, gestures, ocr")//element-wait
                .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                .withArgument(() -> "--config", new File(System.getProperty("user.dir") + File.separator + "config" + File.separator + "serverconfig.json").toString())
                .withTimeout(Duration.ofSeconds(240))
                .withLogOutput(System.err)
                .withLogFile(logFile));
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        AppiumDriverLocalService appiumDriverLocalService = getAppiumDriverService();
        AppiumDriver appiumDriver = null;
        try {
            appiumDriverLocalService.start();

            UiAutomator2Options uiAutomator2Options = new UiAutomator2Options()
                    .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
                    .setApp(System.getProperty("user.dir") + File.separator + "app" + File.separator + "android" + File.separator + "mda-2.0.2-23.apk")
                    .setFullReset(false)
                    .setNoReset(true)
                    .setPlatformName("android")
                    .setPlatformVersion("13")
                    .setUdid("ZD222CJSXB")
                    .setAppPackage("com.saucelabs.mydemoapp.android")
                    .setAppActivity("com.saucelabs.mydemoapp.android.view.activities.SplashActivity");

            uiAutomator2Options.setCapability("shouldTerminateApp", true);

            System.out.println("URL " + appiumDriverLocalService.getUrl());
            appiumDriver = new AndroidDriver(appiumDriverLocalService.getUrl(), uiAutomator2Options);
            System.out.println("SessionID " + appiumDriver.getSessionId());

            Thread.sleep(5000);

            byte[] navMenuByte = FileUtils.readFileToByteArray(new File(System.getProperty("user.dir") + File.separator + "image" + File.separator + "NavMenuIcon.png"));
            String navMenuEncodedString = Base64.getEncoder().encodeToString(navMenuByte);

            appiumDriver.findElement(AppiumBy.image(navMenuEncodedString)).click();

            Thread.sleep(5000);

        } finally {
            if (appiumDriver != null) {
                appiumDriver.quit();
            }
            appiumDriverLocalService.stop();
        }
    }
}
  1. Failed Log when element-wait is passed in --use-plugins https://gist.github.com/dipakkumar1225/207e6ce236f3f6bb27abfcfe6ca7ac1f

  2. Success Log when element-wait plugin is not used in --use-plugins https://gist.github.com/dipakkumar1225/c80de443415e7f15fa486cce78d94e08

Please suggest the solution for this

mykola-mokhnach commented 3 months ago

We do not maintain the element-wait plugin. Please report your issue to plugin authors