Getting issue in WebDriverListener implementation with PageFactory

Appium: 1.22.3
java-client : 8.2.0
Android: Real Device
Application Type: Native app

To capture web driver events, I am using WebDriverListener and getting issue with Page Factory, but same works perfectly when I am locating element using driver.findElement. .

Here is the Webdriver event capture class.

public class DemoWebDriverListener implements WebDriverListener {

   public void beforeFindElement(WebDriver driver, By locator) {
    System.out.println(" Before Find Element " + locator);
   }

   public void afterFindElement(WebDriver driver, By locator, WebElement result) {
    System.out.println(" After Find Element " + locator);
  }
}

Without Page Factory: This works fine, actions performed on the respective element works perfectly and also Web driver events are getting captured successfully.

 AppiumDriver originalAppiumDriver = new AndroidDriver(url, uiAutomator2Options);
 WebDriverListener webDriverListener = new DemoWebDriverListener();
 WebDriver decoratedAppiumDriver = new EventFiringDecorator<>(webDriverListener).decorate(originalAppiumDriver);

 By locatorNavOpenMenu = AppiumBy.accessibilityId("open menu");
 WebElement webElementNavOpenMenu = 
 decoratedAppiumDriver.findElement(locatorNavOpenMenu);
 webElementNavOpenMenu.click();

With Page Factory : Getting error java.lang.IllegalArgumentException: object is not an instance of declaring class

@AndroidFindBy(accessibility = "open menu")
private WebElement webElementNavOpenMenu1;

@AndroidFindBy(accessibility = "menu item log in")
private WebElement webElementMenuItemLogIn1;

AppiumDriver originalAppiumDriver = new AndroidDriver(url, uiAutomator2Options);
WebDriverListener webDriverListener = new DemoWebDriverListener();
WebDriver decoratedAppiumDriver = new EventFiringDecorator<>(webDriverListener).decorate(originalAppiumDriver);
PageFactory.initElements(new AppiumFieldDecorator(decoratedAppiumDriver), this);

webElementNavOpenMenu1.click();
webElementMenuItemLogIn1.click();

Below are the error with PageFactory:

java.lang.IllegalArgumentException: object is not an instance of declaring class

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at io.appium.java_client.pagefactory.ElementInterceptor.getObject(ElementInterceptor.java:40)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.intercept(InterceptorOfASingleElement.java:60)
at org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4.click(<generated>)
at org.example.DemoAppTest.sample(DemoAppTest.java:64)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Sample code attached here

Attached here is log for same.

[Appium] Welcome to Appium v1.22.3
[Appium] Non-default server args:
[Appium] relaxedSecurityEnabled: true
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[debug] [HTTP] Request idempotency key: 457ef6e8-59c7-4205-b6e1-22952ea7b798
[HTTP] → POST /wd/hub/session
[HTTP] {“capabilities”:{“firstMatch”:[{}],“alwaysMatch”:{“appium:app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appium:appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appium:appPackage”:“com.saucelabs.mydemoapp.rn”,“appium:autoGrantPermissions”:true,“appium:automationName”:“UIAutomator2”,“appium:fullReset”:false,“appium:noReset”:true,“platformName”:“android”}}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [null,null,{“firstMatch”:[{}],“alwaysMatch”:{“appium:app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appium:appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appium:appPackage”:“com.saucelabs.mydemoapp.rn”,“appium:autoGrantPermissions”:true,“appium:automationName”:“UIAutomator2”,“appium:fullReset”:false,“appium:noReset”:true,“platformName”:“android”}}]
[debug] [BaseDriver] Event ‘newSessionRequested’ logged at 1668842549714 (12:52:29 GMT+0530 (India Standard Time))
[Appium] Appium v1.22.3 creating new AndroidUiautomator2Driver (v1.70.1) session
[Appium] Applying relaxed security to ‘AndroidUiautomator2Driver’ as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver] “alwaysMatch”: {
[debug] [BaseDriver] “platformName”: “android”,
[debug] [BaseDriver] “appium:app”: “D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,
[debug] [BaseDriver] “appium:appActivity”: “com.saucelabs.mydemoapp.rn.MainActivity”,
[debug] [BaseDriver] “appium:appPackage”: “com.saucelabs.mydemoapp.rn”,
[debug] [BaseDriver] “appium:autoGrantPermissions”: true,
[debug] [BaseDriver] “appium:automationName”: “UIAutomator2”,
[debug] [BaseDriver] “appium:fullReset”: false,
[debug] [BaseDriver] “appium:noReset”: true
[debug] [BaseDriver] },
[debug] [BaseDriver] “firstMatch”: [
[debug] [BaseDriver] {}
[debug] [BaseDriver] ]
[debug] [BaseDriver] }
[BaseDriver] Session created with session id: 04d247e8-014e-4785-ae8d-16b01b402dcc
[BaseDriver] Using local app ‘D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk’
[debug] [UiAutomator2] Checking whether app is actually present
[ADB] Found 2 ‘build-tools’ folders under ‘D:\Software_Installed\Android\Sdk’ (newest first):
[ADB] D:/Software_Installed/Android/Sdk/build-tools/33.0.0
[ADB] D:/Software_Installed/Android/Sdk/build-tools/32.0.0
[ADB] Using ‘adb.exe’ from ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 start-server’
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices
[debug] [ADB] Connected devices: [{“udid”:“ZD2222ZKDN”,“state”:“device”}]
[AndroidDriver] Using device: ZD2222ZKDN
[ADB] Using ‘adb.exe’ from ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 start-server’
[debug] [ADB] Setting device id to ZD2222ZKDN
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell getprop ro.build.version.sdk’
[debug] [ADB] Current device property ‘ro.build.version.sdk’: 31
[ADB] Getting device platform version
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell getprop ro.build.version.release’
[debug] [ADB] Current device property ‘ro.build.version.release’: 12
[debug] [ADB] Device API level: 31
[UiAutomator2] Relaxing hidden api policy
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell ‘settings put global hidden_api_policy_pre_p_apps 1;settings put global hidden_api_policy_p_apps 1;settings put global hidden_api_policy 1’’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN wait-for-device’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell echo ping’
[debug] [AndroidDriver] Pushing settings apk to device…
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package io.appium.settings’
[debug] [ADB] ‘io.appium.settings’ is installed
[debug] [ADB] Getting package info for ‘io.appium.settings’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package io.appium.settings’
[debug] [ADB] The version name of the installed ‘io.appium.settings’ is greater or equal to the application version name (‘3.4.0’ >= ‘3.4.0’)
[debug] [ADB] There is no need to install/upgrade ‘C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\io.appium.settings\apks\settings_apk-debug.apk’
[debug] [ADB] Getting IDs of all ‘io.appium.settings’ processes
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell ‘pgrep --help; echo $?’’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell pgrep -f ([[:blank:]]|^)io.appium.settings([[:blank:]]|$)’
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell appops set io.appium.settings android:mock_location allow’
[debug] [Logcat] Starting logs capture with command: D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN logcat -v threadtime
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to local port 8200
[debug] [ADB] Forwarding system: 8200 to device: 6790
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN forward tcp:8200 tcp:6790’
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package io.appium.uiautomator2.server’
[debug] [ADB] ‘io.appium.uiautomator2.server’ is installed
[debug] [ADB] Getting package info for ‘io.appium.uiautomator2.server’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package io.appium.uiautomator2.server’
[debug] [ADB] The version name of the installed ‘io.appium.uiautomator2.server’ is greater or equal to the application version name (‘4.27.0’ >= ‘4.27.0’)
[debug] [UiAutomator2] io.appium.uiautomator2.server installation state: sameVersionInstalled
[debug] [ADB] Checking app cert for C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk
[ADB] Using ‘apksigner.jar’ from ‘D:\Software_Installed\Android\Sdk\build-tools\33.0.0\lib\apksigner.jar’
[debug] [ADB] Starting apksigner: ‘C:\Program Files\Java\jdk-15.0.2\bin\java.exe’ -Xmx1024M -Xss1m -jar D:\Software_Installed\Android\Sdk\build-tools\33.0.0\lib\apksigner.jar verify --print-certs C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: [email protected], CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[debug] [ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[debug] [ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[debug] [ADB]
[debug] [ADB] sha256 hash did match for ‘appium-uiautomator2-server-v4.27.0.apk’
[ADB] ‘C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk’ is signed with the default certificate
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package io.appium.uiautomator2.server.test’
[debug] [ADB] ‘io.appium.uiautomator2.server.test’ is installed
[debug] [ADB] Checking app cert for C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk
[debug] [ADB] Starting apksigner: ‘C:\Program Files\Java\jdk-15.0.2\bin\java.exe’ -Xmx1024M -Xss1m -jar D:\Software_Installed\Android\Sdk\build-tools\33.0.0\lib\apksigner.jar verify --print-certs C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: [email protected], CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[debug] [ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[debug] [ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[debug] [ADB]
[debug] [ADB] sha256 hash did match for ‘appium-uiautomator2-server-debug-androidTest.apk’
[ADB] ‘C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk’ is signed with the default certificate
[UiAutomator2] Server packages are not going to be (re)installed
[debug] [UiAutomator2] Waiting up to 30000ms for services to be available
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell pm list instrumentation’
[debug] [UiAutomator2] Instrumentation target ‘io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner’ is available
[ADB] Adding packages [“io.appium.settings”,“io.appium.uiautomator2.server”,“io.appium.uiautomator2.server.test”] to Doze whitelist
[debug] [ADB] Got the following command chunks to execute: [[“dumpsys”,“deviceidle”,“whitelist”,“+io.appium.settings”,“;”,“dumpsys”,“deviceidle”,“whitelist”,“+io.appium.uiautomator2.server”,“;”,“dumpsys”,“deviceidle”,“whitelist”,“+io.appium.uiautomator2.server.test”,“;”]]
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys deviceidle whitelist +io.appium.settings ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server.test ;’
[debug] [ADB] Checking app cert for D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk
[debug] [ADB] Starting apksigner: ‘C:\Program Files\Java\jdk-15.0.2\bin\java.exe’ -Xmx1024M -Xss1m -jar D:\Software_Installed\Android\Sdk\build-tools\33.0.0\lib\apksigner.jar verify --print-certs D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: CN=Android Debug, OU=Android, O=Unknown, L=Unknown, ST=Unknown, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: fac61745dc0903786fb9ede62a962b399f7348f0bb6f899b8332667591033b9c
[debug] [ADB] Signer #1 certificate SHA-1 digest: 5e8f16062ea3cd2c4a0d547876baa6f38cabf625
[debug] [ADB] Signer #1 certificate MD5 digest: 20f46148b72d8e5e5ca23d37a4f41490
[debug] [ADB]
[ADB] ‘D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk’ is signed with a non-default certificate
[debug] [ADB] Getting install status for com.saucelabs.mydemoapp.rn
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package com.saucelabs.mydemoapp.rn’
[debug] [ADB] ‘com.saucelabs.mydemoapp.rn’ is installed
[debug] [ADB] Getting package info for ‘com.saucelabs.mydemoapp.rn’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys package com.saucelabs.mydemoapp.rn’
[debug] [ADB] The version name of the installed ‘com.saucelabs.mydemoapp.rn’ is greater or equal to the application version name (‘1.3.0’ >= ‘1.3.0’)
[debug] [ADB] There is no need to install/upgrade ‘D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk’
[debug] [UiAutomator2] Performing shallow cleanup of automation leftovers
[debug] [UiAutomator2] No obsolete sessions have been detected (socket hang up)
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell am force-stop io.appium.uiautomator2.server.test’
[UiAutomator2] Starting UIAutomator2 server 4.27.0
[UiAutomator2] Using UIAutomator2 server from ‘C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk’ and test from ‘C:\Users\deepakv\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk’
[UiAutomator2] Waiting up to 30000ms for UiAutomator2 to be online…
[debug] [ADB] Creating ADB subprocess with args: [“-P”,5037,“-s”,“ZD2222ZKDN”,“shell”,“am”,“instrument”,“-w”,“-e”,“disableAnalytics”,true,“io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner”]
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[WD Proxy] socket hang up
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[WD Proxy] socket hang up
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[WD Proxy] socket hang up
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[WD Proxy] socket hang up
[debug] [Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[WD Proxy] socket hang up
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“None”,“value”:{“message”:“UiAutomator2 Server is ready to accept commands”,“ready”:true}}
[debug] [UiAutomator2] The initialization of the instrumentation process took 5252ms
[debug] [WD Proxy] Matched ‘/session’ to command name ‘createSession’
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8200/wd/hub/session] with body: {“capabilities”:{“firstMatch”:[{“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“android”,“app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appPackage”:“com.saucelabs.mydemoapp.rn”,“autoGrantPermissions”:true,“automationName”:“UIAutomator2”,“fullReset”:false,“noReset”:true},“platformName”:“android”,“app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appPackage”:“com.saucelabs.mydemoapp.rn”,“autoGrantPermissions”:true,“automationName”:“UIAutomator2”,“fullReset”:false,“noReset”:true,“deviceName”:“ZD2222ZKDN”,“deviceUDID”:“ZD2222ZKDN”}],“alwaysMatch”:{}}}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:{“capabilities”:{“firstMatch”:[{“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“android”,“app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appPackage”:“com.saucelabs.mydemoapp.rn”,“autoGrantPermissions”:true,“automationName”:“UIAutomator2”,“fullReset”:false,“noReset”:true},“platformName”:“android”,“app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appPackage”:“com.saucelabs.mydemoapp.rn”,“autoGrantPermissions”:true,“automationName”:“UIAutomator2”,“fullReset”:false,“noReset”:true,“deviceName”:“ZD2222ZKDN”,“deviceUDID”:“ZD2…
[WD Proxy] Determined the downstream protocol as ‘W3C’
[debug] [WD Proxy] Proxying [GET /appium/device/info] to [GET http://127.0.0.1:8200/wd/hub/session/7bb84292-e671-4c05-aaee-5dad2aaa406b/appium/device/info] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:{“androidId”:“05476dfeabd95eaf”,“apiVersion”:“31”,“bluetooth”:{“state”:“OFF”},“brand”:“motorola”,“carrierName”:“AIRTEL”,“displayDensity”:400,“locale”:“en_IN”,“manufacturer”:“motorola”,“model”:“motorola edge 20 fusion”,“networks”:[{“capabilities”:{“SSID”:null,“linkDownBandwidthKbps”:3255,“linkUpstreamBandwidthKbps”:3773,“networkCapabilities”:“NET_CAPABILITY_IMS,NET_CAPABILITY_NOT_METERED,NET_CAPABILITY_TRUSTED,NET_CAPABILITY_NOT_VPN,NET_CAPABILITY_VALIDATED,NET_CAPABILITY_NOT_ROAMING,NET_CAPABILITY_FOREGROUND,NET_CAPABILITY_NOT_CONGESTED,NET_CAPABILITY_NOT_SUSPENDED”,“signalStrength”:-2147483648,“transportTypes”:“TRANSPORT_CELLULAR”},“detailedState”:“CONNECTED”,“extraInfo”:“ims”,“isAvailable”:true,“isConnected”:true,“isFailover”:false,“isRoaming”:false,“state”:“CONNECTED”,“subtype”:18,“subtypeName”:“IWLAN”,“type”:0,“typeName”:“MOBILE”},{“capabilities”:{“SSID”:null,“linkDownBandwidthKbps”:3255,“linkUpstreamBandwidthKbps”:3773,“networkCapabilities”:”…
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell dumpsys window’
[AndroidDriver] Screen already unlocked, doing nothing
[UiAutomator2] Starting 'com.saucelabs.mydemoapp.rn/com.saucelabs.mydemoapp.rn.MainActivity and waiting for ‘com.saucelabs.mydemoapp.rn/com.saucelabs.mydemoapp.rn.MainActivity’
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell am start -W -n com.saucelabs.mydemoapp.rn/com.saucelabs.mydemoapp.rn.MainActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000’
[debug] [WD Proxy] Proxying [GET /appium/device/pixel_ratio] to [GET http://127.0.0.1:8200/wd/hub/session/7bb84292-e671-4c05-aaee-5dad2aaa406b/appium/device/pixel_ratio] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:2.5}
[debug] [WD Proxy] Matched ‘/appium/device/system_bars’ to command name ‘getSystemBars’
[debug] [WD Proxy] Proxying [GET /appium/device/system_bars] to [GET http://127.0.0.1:8200/wd/hub/session/7bb84292-e671-4c05-aaee-5dad2aaa406b/appium/device/system_bars] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:{“statusBar”:100}}
[debug] [WD Proxy] Matched ‘/window/current/size’ to command name ‘getWindowSize’
[debug] [WD Proxy] Proxying [GET /window/current/size] to [GET http://127.0.0.1:8200/wd/hub/session/7bb84292-e671-4c05-aaee-5dad2aaa406b/window/current/size] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:{“height”:2275,“width”:1080}}
[Appium] New AndroidUiautomator2Driver session created successfully, session 04d247e8-014e-4785-ae8d-16b01b402dcc added to master session list
[debug] [BaseDriver] Event ‘newSessionStarted’ logged at 1668842563616 (12:52:43 GMT+0530 (India Standard Time))
[debug] [W3C (04d247e8)] Cached the protocol value ‘W3C’ for the new session 04d247e8-014e-4785-ae8d-16b01b402dcc
[debug] [W3C (04d247e8)] Responding to client with driver.createSession() result: {“capabilities”:{“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“android”,“app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appPackage”:“com.saucelabs.mydemoapp.rn”,“autoGrantPermissions”:true,“automationName”:“UIAutomator2”,“fullReset”:false,“noReset”:true},“platformName”:“android”,“app”:“D:\Workspace\Project\Appium\DemoAppium\untitled\src\test\resources\Android-MyDemoAppRN.1.3.0.build-244.apk”,“appActivity”:“com.saucelabs.mydemoapp.rn.MainActivity”,“appPackage”:“com.saucelabs.mydemoapp.rn”,“autoGrantPermissions”:true,“automationName”:“UIAutomator2”,“fullReset”:false,“noReset”:true,“deviceName”:“ZD2222ZKDN”,“deviceUDID”:“ZD2222ZKDN”,“deviceApiLevel”:31,“platformVersion”:“12”,“deviceScreenSize”:“108…
[HTTP] ← POST /wd/hub/session 200 13909 ms - 1289
[HTTP]
[HTTP] → GET /wd/hub/session/04d247e8-014e-4785-ae8d-16b01b402dcc/context
[HTTP] {}
[debug] [W3C (04d247e8)] Calling AppiumDriver.getCurrentContext() with args: [“04d247e8-014e-4785-ae8d-16b01b402dcc”]
[debug] [W3C (04d247e8)] Responding to client with driver.getCurrentContext() result: “NATIVE_APP”
[HTTP] ← GET /wd/hub/session/04d247e8-014e-4785-ae8d-16b01b402dcc/context 200 32 ms - 22
[HTTP]
[HTTP] → POST /wd/hub/session/04d247e8-014e-4785-ae8d-16b01b402dcc/element
[HTTP] {“using”:“accessibility id”,“value”:“open menu”}
[debug] [W3C (04d247e8)] Calling AppiumDriver.findElement() with args: [“accessibility id”,“open menu”,“04d247e8-014e-4785-ae8d-16b01b402dcc”]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [WD Proxy] Matched ‘/element’ to command name ‘findElement’
[debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8200/wd/hub/session/7bb84292-e671-4c05-aaee-5dad2aaa406b/element] with body: {“strategy”:“accessibility id”,“selector”:“open menu”,“context”:”",“multiple”:false}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:{“ELEMENT”:“00000000-0000-5448-ffff-ffff00000022”,“element-6066-11e4-a52e-4f735466cecf”:“00000000-0000-5448-ffff-ffff00000022”}}
[debug] [W3C (04d247e8)] Responding to client with driver.findElement() result: {“element-6066-11e4-a52e-4f735466cecf”:“00000000-0000-5448-ffff-ffff00000022”,“ELEMENT”:“00000000-0000-5448-ffff-ffff00000022”}
[HTTP] ← POST /wd/hub/session/04d247e8-014e-4785-ae8d-16b01b402dcc/element 200 62 ms - 137
[HTTP]
[Appium] Received SIGINT - shutting down
[debug] [Appium] Cleaning up 1 active session
[Appium] Closing session, cause was ‘The process has received SIGINT signal’
[Appium] Removing session ‘04d247e8-014e-4785-ae8d-16b01b402dcc’ from our master session list
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [WD Proxy] Matched ‘/’ to command name ‘deleteSession’
[debug] [WD Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8200/wd/hub/session/7bb84292-e671-4c05-aaee-5dad2aaa406b] with no body
[Logcat] Logcat terminated with code 3221225786, signal null
[debug] [Instrumentation] The process has exited with code 3221225786
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“7bb84292-e671-4c05-aaee-5dad2aaa406b”,“value”:null}
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell am force-stop com.saucelabs.mydemoapp.rn’
[debug] [Logcat] Stopping logcat capture
[debug] [Logcat] Logcat already stopped
[debug] [ADB] Removing forwarded port socket connection: 8200
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN forward --remove tcp:8200’
[UiAutomator2] Restoring hidden api policy to the device default configuration
[debug] [ADB] Running ‘D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell ‘settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy’’

Now I am able to interact with element

Instead of

PageFactory.initElements(new AppiumFieldDecorator(baseMobileDriver), this);

now I am using this.

PageFactory.initElements(new AppiumElementLocatorFactory(decoratedAppiumDriver, Duration.ofSeconds(5), new DefaultElementByBuilder(MobilePlatform.ANDROID, AutomationName.ANDROID_UIAUTOMATOR2)), this);

So can any please explain the difference between this.
AppiumElementLocatorFactory vs AppiumFieldDecorator

This is getting failed in the case of List elements and Webview:

Error displayed List Elements:

java.lang.NullPointerException: Cannot invoke “java.util.List.stream()” because “this.webElementListMenuNames” is null

at org.example.DemoAppTest.withPageFactory(DemoAppTest.java:147)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Error displayed for webview:

java.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$Y0aK7OFI cannot be cast to class io.appium.java_client.android.AndroidDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$Y0aK7OFI is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @37fdfb05; io.appium.java_client.android.AndroidDriver is in unnamed module of loader ‘app’)

I was searching java-client API doc and there I found that.in java-client 8.0.0 Listener was deprecated and from version 8.1.0 onward this has been removed.

Finally, after adding this two resolve the error.

PageFactory.initElements(new AppiumFieldDecorator(decoratedAppiumDriver), this);

PageFactory.initElements(new AppiumElementLocatorFactory(decoratedAppiumDriver, Duration.ofSeconds(1), new DefaultElementByBuilder(MobilePlatform.ANDROID, AutomationName.ANDROID_UIAUTOMATOR2)), this);

for WebView I am using the original driver

But still, I am not fully understanding the difference between AppiumFieldDecorator and AppiumElementLocatorFactory

Is this being valid approach?

Updated code attached here