java-client icon indicating copy to clipboard operation
java-client copied to clipboard

isDisplayed() error, Method is not implemented. Conditional try catch implementation is not working

Open OnurSerbes opened this issue 2 years ago • 9 comments

The problem

I am trying to check if the element is present or not, so I am using "isDisplayed()" but it gives me "Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Method is not implemented" error. I checked the other issues most of them are about the client version. I updated all my clients but still gives me the error.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.22.3
  • Desktop OS/version used to run Appium: Windows 10
  • Node.js version (unless using Appium.app|exe): 16.14.0
  • Npm or Yarn package manager: npm 8.16.0
  • Mobile platform/version under test: Android 12
  • Real device or emulator/simulator: Real device
  • Appium CLI or Appium.app|exe: from directly cmd

Details

I also tried with conditions but instead of catches and continues to run, it is just throwing me the error


isElementPresented(By.xpath("blabla"));

 public static boolean isElementPresented(By by){
        try{
            driver.findElement(by);
            System.out.println("store found");
            return true;
        }catch (NoSuchElementException e ){
            System.out.println("store not found");
            return false;
        }
    }

"store found" shows but false condition is not working"

Log of conditional run https://gist.github.com/OnurSerbes/6f0cecae55fdefb722d6f73a009897d8

Link to Appium logs

Appium Log https://gist.github.com/OnurSerbes/ea942168570a938fc5cb0365347d6026

Editor Log https://gist.github.com/OnurSerbes/3ddefe92a95617aa5e64b290f3bbcb1f

Code To Reproduce Issue [ Good To Have ]

if(driver.findElement(By.xpath("blabla")).isDisplayed()){
            WebElement store = driver.findElement(By.xpath("blabla"));
            String storeText = store.getText();
            System.out.println("store: " + storeText);
        }

OnurSerbes avatar Oct 14 '22 10:10 OnurSerbes

[HTTP] --> POST /wd/hub/session/70ec64eb-468f-4cb7-962b-a8ff8755a425/execute/sync [HTTP] {"script":"return (function(){return (function(){var k=this||self;function aa(a){return"string"==typeof a}function ba(a,b){a=a.split(".");var c=k;a[0]in c||"undefined"==typeof c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)a.length||void 0===b?c[d]&&c[d]!==Object.prototype[d]?c=c[d]:c=c[d]={}:c[d]=b}\nfunction ca(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";\nelse if("function"==b&&"undefined"==typeof a.call)return"object";return b}function da(a,b,c){return a.cal...

This is not a server issue, but rather the client one. It sends some random script to the endpoint instead of calling it properly. Are you sure you use the proper client?

mykola-mokhnach avatar Oct 14 '22 15:10 mykola-mokhnach

I was using those two from the beginning. Normaly it's working without any problem. My automation is working, but when I tried to use isDisplayed() it gives me the error.

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.5.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>8.2.0</version>
        </dependency>

OnurSerbes avatar Oct 14 '22 17:10 OnurSerbes

From which class do you inherit the driver instance?

mykola-mokhnach avatar Oct 14 '22 18:10 mykola-mokhnach

This is the java file that I used. You can see the all implementation from here https://gist.github.com/OnurSerbes/b870f0b14ea2b010413aae5e8d08c0e8

OnurSerbes avatar Oct 14 '22 18:10 OnurSerbes

    driver = new RemoteWebDriver(url, cap);

RemoteWebDriver is targeting web browsers. Consider using mobile-specific driver classes imported from java-client instead.

mykola-mokhnach avatar Oct 14 '22 18:10 mykola-mokhnach

I changed it with AndroidDriver (you can check the gist again), and uncommented this block

        if (driver.findElement(By.xpath("blabla")).isDisplayed()) {
            WebElement store = driver.findElement(By.xpath("blabla"));
            String storeText = store.getText();
            System.out.println("store: " + storeText);
        } else {
            String storeText = "individual";
            System.out.println("store: " + storeText);
        }

but still gives me the same error when a page with no element comes in

49866 [AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Adding key: http://127.0.0.1:4723 for channel [id: 0x3c00e02f, L:/127.0.0.1:60086 - R:/127.0.0.1:4723] Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element Build info: version: '4.5.0', revision: 'fe167b119a' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17' Driver info: io.appium.java_client.android.AndroidDriver Command: [e50f2831-6572-4067-8601-813eff59e196, findElement {using=xpath, value=/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView}] Capabilities {appium:appActivity: com.sahibinden.ui.browsing...., appium:appPackage: com.sahibinden, appium:databaseEnabled: false, appium:desired: {appActivity: com.sahibinden.ui.browsing...., appPackage: com.sahibinden, deviceName: Redmi Redmi Note 9S, noReset: true, platformName: android, platformVersion: 11, udid: 89530f89}, appium:deviceApiLevel: 30, appium:deviceManufacturer: Xiaomi, appium:deviceModel: Redmi Note 9 Pro, appium:deviceName: 89530f89, appium:deviceScreenDensity: 440, appium:deviceScreenSize: 1080x2400, appium:deviceUDID: 89530f89, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:noReset: true, appium:pixelRatio: 2.75, appium:platformVersion: 11, appium:statBarHeight: 102, appium:takesScreenshot: true, appium:udid: 89530f89, appium:viewportRect: {height: 2066, left: 0, top: 102, width: 1080}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID} Session ID: e50f2831-6572-4067-8601-813eff59e196 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200) at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133) at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:189) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547) at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:162) at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:60) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:365) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:357) at AppTest.readData(AppTest.java:111) at AppTest.openApp(AppTest.java:91) at AppTest.main(AppTest.java:25)

Process finished with exit code 1

OnurSerbes avatar Oct 14 '22 18:10 OnurSerbes

Try https://github.com/appium/appium-uiautomator2-driver#elements-cannot-be-found

Maybe the element does not really exist. Did you check the actual page source?

mykola-mokhnach avatar Oct 14 '22 19:10 mykola-mokhnach

In some pages it exists I can take the text but some of them don't have it, that is the reason why I am using isDisplayed() am I using wrong ? As I stated, I also tried to avoid it without using isDisplayed() (with isElementPresent function but it's not working either) because of the prevent error.

OnurSerbes avatar Oct 14 '22 19:10 OnurSerbes

Probably you have issues understanding the concept of existence/visibility of elements. Try asking at Appium forum about it. You could start at https://discuss.appium.io/t/help-needed-expectedconditions-invisibilityof

mykola-mokhnach avatar Oct 14 '22 19:10 mykola-mokhnach

I am getting

org.openqa.selenium.UnsupportedCommandException: {"value":{"error":"unknown method","message":"Method is not implemented","stacktrace":"NotImplementedError: Method is not implemented\n at AndroidUiautomator2Driver.execute (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/appium-android-driver/lib/commands/execute.js:13:11)\n at commandExecutor (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/@appium/base-driver/lib/basedriver/driver.ts:107:18)\n at /home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/async-lock/lib/index.js:171:12\n at AsyncLock._promiseTry (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/async-lock/lib/index.js:304:31)\n at exec (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/async-lock/lib/index.js:170:9)\n at AsyncLock.acquire (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/async-lock/lib/index.js:187:3)\n at AndroidUiautomator2Driver.executeCommand (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/@appium/base-driver/lib/basedriver/driver.ts:123:39)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at defaultBehavior (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/appium/lib/appium.js:684:14)\n at AppiumDriver.executeWrappedCommand (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/appium/lib/appium.js:774:16)\n at AppiumDriver.executeCommand (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/appium/lib/appium.js:696:17)\n at asyncHandler (/home/ltadmin/Documents/appium/2.0-stable-5-4-24/node_modules/@appium/base-driver/lib/protocol/protocol.js:393:19)"}} Command duration or timeout: 316 milliseconds Build info: version: '4.8.1', revision: '8ebccac989' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.215-203.850.amzn2.x86_64', java.version: '17.0.5' Driver info: org.openqa.selenium.remote.RemoteWebDriver Command: [02f37e51-658d-4de3-9dc8-e0f94c661e0d, isElementDisplayed {id=00000000-0000-3c8b-ffff-ffff0000005d}] Capabilities {adbExecTimeout: 120000, appActivity: com.maz.combo1126.MainActivity, appPackage: com.maz.combo1126, autoAcceptAlerts: true, autoGrantPermissions: true, automationName: uiautomator2, chromeOptions: {args: []}, chromedriverExecutableDir: /appium/assets/drivers/chro..., chromedriverPorts: [[11001, 11049]], databaseEnabled: false, desired: {adbExecTimeout: 120000, appActivity: com.maz.combo1126.MainActivity, appPackage: com.maz.combo1126, autoAcceptAlerts: true, autoGrantPermissions: true, automationName: uiautomator2, chromeOptions: {args: []}, chromedriverExecutableDir: /appium/assets/drivers/chro..., chromedriverPorts: [[11001, 11049]], deviceName: Galaxy S23, headless: false, nativeWebScreenshot: true, newCommandTimeout: 0, orientation: PORTRAIT, platformName: android, platformVersion: 13, systemPort: 12192, udid: R3CW30P8AVF, uiautomator2ServerLaunchTimeout: 60000, waitForQuiescence: false}, deviceApiLevel: 33, deviceManufacturer: samsung, deviceModel: SM-S911U1, deviceName: R3CW30P8AVF, deviceScreenDensity: 480, deviceScreenSize: 1080x2340, deviceUDID: R3CW30P8AVF, headless: false, javascriptEnabled: true, locationContextEnabled: false, nativeWebScreenshot: true, networkConnectionEnabled: true, newCommandTimeout: 0, orientation: PORTRAIT, pixelRatio: 3, platform: LINUX, platformName: ANDROID, platformVersion: 13, statBarHeight: 81, systemPort: 12192, takesScreenshot: true, udid: R3CW30P8AVF, uiautomator2ServerLaunchTimeout: 60000, viewportRect: {height: 2034, left: 0, top: 81, width: 1080}, waitForQuiescence: false, warnings: {}, webStorageEnabled: false} Element: [[RemoteWebDriver: on ANDROID (02f37e51-658d-4de3-9dc8-e0f94c661e0d)] -> xpath: (//XCUIElementTypeLink[@name='card'])[1] | (//android.view.View[@resource-id='card'])[1]] Session ID: 02f37e51-658d-4de3-9dc8-e0f94c661e0d at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:217) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:169) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:257) at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:313) at step_definitions.GlobalStepDefs.articleVerification(GlobalStepDefs.java:449) at ✽.verify article "1" is visible(file:///jenkins/jenkins/workspace/_mobile-framework_lambdatest_new/src/test/resources/features/HomeScreen.feature:8)

when running the script in the lambdatest but same is working fine in my local emulators

ayushverma864 avatar May 20 '24 06:05 ayushverma864