appium / python-client

Python language bindings for Appium
Apache License 2.0
1.67k stars 561 forks source link

Getting kAXErrorServerNotFound error when trying to automate ios application and as well as when trying to inspect for elements #1044

Closed suneel944 closed 1 week ago

suneel944 commented 2 weeks ago

The problem

I am trying to automate a jailbroken ios that is a rootless one using palera1n and the command used to jail break rootless --> palera1n -l (its L small case) and I am using iPhone 8 for automation purpose and below are some of the details which might be handy:

Environment

Details

Appium inspector state:

image

appium inspector version:

image

I am not able to inspect the elements for a specific side loaded application and the device is jailbroken. The appium inspector fails to pick up the page source of the application

Appium Logs

[21d0828f][XCUITestDriver@e77d] Not clearing log files. Use `clearSystemFiles` capability to turn on.
[21d0828f][AppiumDriver@9bd4] Event 'quitSessionFinished' logged at 1728582749118 (21:52:29 GMT+0400 (Gulf Standard Time))
[21d0828f][AppiumDriver@9bd4] Received response: null
[21d0828f][AppiumDriver@9bd4] But deleting session, so not returning
[21d0828f][AppiumDriver@9bd4] Responding to client with driver.deleteSession() result: null
[21d0828f][HTTP] <-- DELETE /session/21d0828f-0b0e-4147-8dff-db38482a1041 200 1104 ms - 14 
[21d0828f][iProxy@78d3386f:8100] The connection has been closed
[HTTP] --> POST /session {"capabilities":{"alwaysMatch":{"appium:platformName":"iOS","appium:platformVersion":"16.7","appium:automationName":"XCUITest","appium:bundleId":"cn.tinyapps.RST","appium:udid":"78********************","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},"firstMatch":[{}]},"desiredCapabilities":{"appium:platformName":"iOS","appium:platformVersion":"16.7","appium:automationName":"XCUITest","appium:bundleId":"cn.tinyapps.RST","appium:udid":"78********************","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true}}
[AppiumDriver@9bd4] Calling AppiumDriver.createSession() with args: [{"appium:platformName":"iOS","appium:platformVersion":"16.7","appium:automationName":"XCUITest","appium:bundleId":"cn.tinyapps.RST","appium:udid":"78********************","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},null,{"alwaysMatch":{"appium:platformName":"iOS","appium:platformVersion":"16.7","appium:automationName":"XCUITest","appium:bundleId":"cn.tinyapps.RST","appium:udid":"78********************","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},"firstMatch":[{}]}]
[AppiumDriver@9bd4] Event 'newSessionRequested' logged at 1728582841790 (21:54:01 GMT+0400 (Gulf Standard Time))
[BaseDriver] The capabilities ["platformName"] are standard capabilities and do not require "appium:" prefix
[Appium] Attempting to find matching driver for automationName 'XCUITest' and platformName 'iOS'
[Appium] The 'xcuitest' driver was installed and matched caps.
[Appium] Will require it at /Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver
[Appium] Requiring driver at /Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/build/index.js
[AppiumDriver@9bd4] Appium v2.11.5 creating new XCUITestDriver (v7.27.0) session
[AppiumDriver@9bd4] Checking BaseDriver versions for Appium and XCUITestDriver
[AppiumDriver@9bd4] Appium's BaseDriver version is 9.11.5
[AppiumDriver@9bd4] XCUITestDriver's BaseDriver version is 9.11.5
[XCUITestDriver@f6d9] 
[XCUITestDriver@f6d9] Creating session with W3C capabilities: {
  "alwaysMatch": {
    "platformName": "iOS",
    "appium:platformVersion": "16.7",
    "appium:automationName": "XCUITest",
    "appium:bundleId": "cn.tinyapps.RST",
    "appium:udid": "78********************",
    "appium:newCommandTimeout": 3600,
    "appium:connectHardwareKeyboard": true
  },
  "firstMatch": [
    {}
  ]
}
[14d0cad6][XCUITestDriver@f6d9] Session created with session id: 14d0cad6-8ef2-4a38-8807-b40b1a77170a
[14d0cad6][XCUITest] Current user: 'suneel.subramanya'
[14d0cad6][XCUITestDriver@f6d9] Available real devices: 78********************
[14d0cad6][XCUITestDriver@f6d9] Creating iDevice object with udid '78********************'
[14d0cad6][XCUITestDriver@f6d9] Determining device to run tests on: udid: '78********************', real device: true
[14d0cad6][XCUITestDriver@f6d9] Event 'xcodeDetailsRetrieved' logged at 1728582841817 (21:54:01 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Event 'appConfigured' logged at 1728582841817 (21:54:01 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Event 'resetStarted' logged at 1728582841817 (21:54:01 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Reset: running ios real device reset flow
[14d0cad6][XCUITestDriver@f6d9] Event 'resetComplete' logged at 1728582841817 (21:54:01 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Using WDA path: '/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent'
[14d0cad6][XCUITestDriver@f6d9] Using WDA agent: '/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj'
[14d0cad6][XCUITestDriver@f6d9] The pyidevice tool is not present in PATH. Skipping crash logs collection for real devices.
[14d0cad6][XCUITestDriver@f6d9] Event 'logCaptureStarted' logged at 1728582841932 (21:54:01 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Setting up real device
[14d0cad6][XCUITestDriver@f6d9] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found
[14d0cad6][DevCon Factory] Requesting connection for device 78******************** on local port 8100, device port 8100
[14d0cad6][DevCon Factory] Cached connections count: 0
[14d0cad6][DevCon Factory] Successfully requested the connection for 78********************:8100
[14d0cad6][XCUITestDriver@f6d9] Starting WebDriverAgent initialization with the synchronization key 'XCUITestDriver'
[14d0cad6][WD Proxy] Matched '/status' to command name 'getStatus'
[14d0cad6][WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[14d0cad6][WD Proxy] Got response with status 200: {"value":{"build":{"upgradedAt":"1728406752888","version":"8.9.2","time":"Oct 10 2024 02:59:25","productBundleIdentifier":"com.facebook.WebDriverAgentRunner"},"os":{"testmanagerdVersion":65535,"name":"iOS","sdkVersion":"18.0","version":"16.7.10"},"device":"iphone","ios":{"ip":"192.168.0.144"},"message":"WebDriverAgent is ready to accept commands","state":"success","ready":true},"sessionId":null}
[14d0cad6][XCUITestDriver@f6d9] Upgrade timestamp of the currently bundled WDA: 1728406752888
[14d0cad6][XCUITestDriver@f6d9] Upgrade timestamp of the WDA on the device: 1728406752888
[14d0cad6][XCUITestDriver@f6d9] Will reuse previously cached WDA instance at 'http://127.0.0.1:8100/' with 'com.facebook.WebDriverAgentRunner'. Set the wdaLocalPort capability to a value different from 8100 if this is an undesired behavior.
[14d0cad6][XCUITestDriver@f6d9] Trying to start WebDriverAgent 1 times with 10000ms interval
[14d0cad6][XCUITestDriver@f6d9] These values can be customized by changing wdaStartupRetries/wdaStartupRetryInterval capabilities
[14d0cad6][XCUITestDriver@f6d9] Event 'wdaStartAttempted' logged at 1728582842176 (21:54:02 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Using provided WebdriverAgent at 'http://127.0.0.1:8100/'
[14d0cad6][WD Proxy] Matched '/status' to command name 'getStatus'
[14d0cad6][WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[14d0cad6][WD Proxy] Got response with status 200: {"value":{"build":{"upgradedAt":"1728406752888","version":"8.9.2","time":"Oct 10 2024 02:59:25","productBundleIdentifier":"com.facebook.WebDriverAgentRunner"},"os":{"testmanagerdVersion":65535,"name":"iOS","sdkVersion":"18.0","version":"16.7.10"},"device":"iphone","ios":{"ip":"192.168.0.144"},"message":"WebDriverAgent is ready to accept commands","state":"success","ready":true},"sessionId":null}
[14d0cad6][XCUITestDriver@f6d9] Event 'wdaSessionAttempted' logged at 1728582842191 (21:54:02 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Sending createSession command to WDA
[14d0cad6][XCUITestDriver@f6d9] Matched '/session' to command name 'createSession'
[14d0cad6][XCUITestDriver@f6d9] Proxying [POST /session] to [POST http://127.0.0.1:8100/session] with body: {"capabilities":{"firstMatch":[{"bundleId":"cn.tinyapps.RST","arguments":[],"environment":{},"eventloopIdleDelaySec":0,"shouldWaitForQuiescence":true,"shouldUseTestManagerForVisibilityDetection":false,"maxTypingFrequency":60,"shouldUseSingletonTestManager":true,"shouldTerminateApp":true,"forceAppLaunch":true,"useNativeCachingStrategy":true,"forceSimulatorSoftwareKeyboardPresence":false}],"alwaysMatch":{}}}
[14d0cad6][XCUITestDriver@f6d9] Parsed BUILD_DIR configuration value: '/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/build'
[14d0cad6][XCUITestDriver@f6d9] Got derived data root: '/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules'
[14d0cad6][XCUITestDriver@f6d9] Got response with status 200: {"value":{"sessionId":"57270DAE-310D-4CF2-A719-736F7C12430F","capabilities":{"sdkVersion":"16.7.10","device":"iphone"}},"sessionId":"57270DAE-310D-4CF2-A719-736F7C12430F"}
[14d0cad6][XCUITestDriver@f6d9] Determined the downstream protocol as 'W3C'
[14d0cad6][XCUITestDriver@f6d9] WDA session startup took 2149ms
[14d0cad6][XCUITestDriver@f6d9] Event 'wdaSessionStarted' logged at 1728582844340 (21:54:04 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Event 'wdaStarted' logged at 1728582844340 (21:54:04 GMT+0400 (Gulf Standard Time))
[14d0cad6][BaseDriver] The value of 'elementResponseAttributes' setting did not change. Skipping the update for it
[14d0cad6][BaseDriver] The value of 'shouldUseCompactResponses' setting did not change. Skipping the update for it
[14d0cad6][AppiumDriver@9bd4] New XCUITestDriver session created successfully, session 14d0cad6-8ef2-4a38-8807-b40b1a77170a added to master session list
[14d0cad6][AppiumDriver@9bd4] Event 'newSessionStarted' logged at 1728582844340 (21:54:04 GMT+0400 (Gulf Standard Time))
[14d0cad6][XCUITestDriver@f6d9] Cached the protocol value 'W3C' for the new session 14d0cad6-8ef2-4a38-8807-b40b1a77170a
[14d0cad6][XCUITestDriver@f6d9] Responding to client with driver.createSession() result: {"capabilities":{"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"platformName":"iOS","platformVersion":"16.7","automationName":"XCUITest","bundleId":"cn.tinyapps.RST","udid":"78********************","newCommandTimeout":3600,"connectHardwareKeyboard":true}}
[14d0cad6][HTTP] <-- POST /session 200 2552 ms - 484 
[14d0cad6][HTTP] --> GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/appium/settings {}
[14d0cad6][XCUITestDriver@f6d9] Calling AppiumDriver.getSettings() with args: ["14d0cad6-8ef2-4a38-8807-b40b1a77170a"]
[14d0cad6][XCUITestDriver@f6d9] Executing command 'getSettings'
[14d0cad6][XCUITestDriver@f6d9] Responding to client with driver.getSettings() result: {"nativeWebTap":false,"nativeWebTapStrict":false,"useJSONSource":false,"webScreenshotMode":"native","shouldUseCompactResponses":true,"elementResponseAttributes":"type,label","mjpegServerScreenshotQuality":25,"mjpegServerFramerate":10,"screenshotQuality":1,"mjpegScalingFactor":100,"reduceMotion":null,"pageSourceExcludedAttributes":""}
[14d0cad6][HTTP] <-- GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/appium/settings 200 1 ms - 345 
[14d0cad6][HTTP] --> GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/screenshot {}
[14d0cad6][XCUITestDriver@f6d9] Calling AppiumDriver.getScreenshot() with args: ["14d0cad6-8ef2-4a38-8807-b40b1a77170a"]
[14d0cad6][XCUITestDriver@f6d9] Executing command 'getScreenshot'
[14d0cad6][XCUITestDriver@f6d9] Taking screenshot with WDA
[14d0cad6][XCUITestDriver@f6d9] Matched '/screenshot' to command name 'getScreenshot'
[14d0cad6][XCUITestDriver@f6d9] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/57270DAE-310D-4CF2-A719-736F7C12430F/screenshot] with no body
[14d0cad6][XCUITestDriver@f6d9] Got response with status 200: {"value":"iVBORw0KGgoAAAANSUhEUgAAAu4AAAU2CAIAAABFtaRRAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAC7qADAAQAAAABAAAFNgAAAACw0axrAAAAHGlET1QAAAACAAAAAAAAApsAAAAoAAACmwAAApsAANtiQNU9bQAAQABJREFUeAHsnQd4FEUDhkNClyaCqCCCgmBDLNgb9vKLXcSCioiAgDSRItJ7701K6L33GjqE3kJvCYSWvlxAUfb/ZuZ2s9eSu0uCXPLdM89lMzv1ndmd76YGaUlXaUiABEiABEiABEggQAkEBWi6mWwSIAESIAESIAESAAFKGXZKkQAJkAAJkAAJBDABSpkALjyKcRIgARIgARIgAUoZShkSIAESIAESIIEAJkApE8CFRyVOAiRAAiRAAjcxgWQtCSbT21lKmUxHfANKkVGQAAmQAAmQwM1HgFIm83VcppW6KjxP3xRPJEACJEACJHAzE/DUfnltr9k0zRYVdXbfvgOyY8Zrj3714rBXJjMqU+pllhkxMkwSIAESIAESyCgCohVLTLi8LXzn9GmzRo4YPXjQsIEDhgzoPzhNM2jg0F079yYlXT537kJQUHCuXHkQVEK8tnrVWrd+ESwCRxSICNEhUj96GQJLyiiJkFFFlVHhyFRJBaoZn4iIiFWrVk2ePLlfv36tWrXCN65hA3sIVWGE8ITJqDQwHBJwJaDqGGuaKxnakAAJeCJgf2+cP3dp4oQpUnwMHdDfWzNwwLC1a9cnJmqJiYlFixYNCgopeVdptHQXL8SHjpucajh2kYRIEbWv7SOljKfi9N5eFrxmi49PXL58eaNGjUqXLp0/f/7ChQsXKlQoX758ISEh+MY1bGBfunSZRo0aL1u6Mj4uiVKGBDKTAKWM908xXZIACSgC4r2BrhGlY/4cNXbXzv3nz8UmxOMXuHeI5M/1F19...
[14d0cad6][XCUITestDriver@f6d9] Responding to client with driver.getScreenshot() result: "iVBORw0KGgoAAAANSUhEUgAAAu4AAAU2CAIAAABFtaRRAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAC7qADAAQAAAABAAAFNgAAAACw0axrAAAAHGlET1QAAAACAAAAAAAAApsAAAAoAAACmwAAApsAANtiQNU9bQAAQABJREFUeAHsnQd4FEUDhkNClyaCqCCCgmBDLNgb9vKLXcSCioiAgDSRItJ7701K6L33GjqE3kJvCYSWvlxAUfb/ZuZ2s9eSu0uCXPLdM89lMzv1ndmd76YGaUlXaUiABEiABEiABEggQAkEBWi6mWwSIAESIAESIAESAAFKGXZKkQAJkAAJkAAJBDABSpkALjyKcRIgARIgARIgAUoZShkSIAESIAESIIEAJkApE8CFRyVOAiRAAiRAAjcxgWQtCSbT21lKmUxHfANKkVGQAAmQAAmQwM1HgFIm83VcppW6KjxP3xRPJEACJEACJHAzE/DUfnltr9k0zRYVdXbfvgOyY8Zrj3714rBXJjMqU+pllhkxMkwSIAESIAESyCgCohVLTLi8LXzn9GmzRo4YPXjQsIEDhgzoPzhNM2jg0F079yYlXT537kJQUHCuXHkQVEK8tnrVWrd+ESwCRxSICNEhUj96GQJLyiiJkFFFlVHhyFRJBaoZn4iIiFWrVk2ePLlfv36tWrXCN65hA3sIVWGE8ITJqDQwHBJwJaDqGGuaKxnakAAJeCJgf2+cP3dp4oQpUnwMHdDfWzNwwLC1a9cnJmqJiYlFixYNCgopeVdptHQXL8SHjpucajh2kYRIEbWv7SOljKfi9N5eFrxmi49PXL58eaNGjUqXLp0/f/7ChQsXKlQoX758ISEh+MY1bGBfunSZRo0aL1u6Mj4uiVKGBDKTAKWM908xXZIACSgC4r2BrhGlY/4cNXbXzv3nz8UmxOMXuHeI5M/1F198MUh8QlYs...
[14d0cad6][HTTP] <-- GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/screenshot 200 170 ms - 157720 
[14d0cad6][HTTP] --> GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/window/rect {}
[14d0cad6][XCUITestDriver@f6d9] Calling AppiumDriver.getWindowRect() with args: ["14d0cad6-8ef2-4a38-8807-b40b1a77170a"]
[14d0cad6][XCUITestDriver@f6d9] Executing command 'getWindowRect'
[14d0cad6][XCUITestDriver@f6d9] Proxying [GET /window/size] to [GET http://127.0.0.1:8100/session/57270DAE-310D-4CF2-A719-736F7C12430F/window/size] with no body
[14d0cad6][XCUITestDriver@f6d9] Got response with status 404: {"value":{"error":"stale element reference","message":"The previously found element \"Application 'cn.tinyapps.RST'\" is not present in the current view anymore. Make sure the application UI has the expected state. Original error: Error getting main window kAXErrorServerNotFound","traceback":"(\n\t0   CoreFoundation                      0x00000001b6921418 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 37912\n\t1   libobjc.A.dylib                     0x00000001afc01c28 objc_exception_throw + 56\n\t2   WebDriverAgentLib                   0x000000010602c820 -[XCUIElement(FBUtilities) fb_takeSnapshot] + 756\n\t3   WebDriverAgentLib                   0x0000000106023640 -[XCUIElement(WebDriverAttributesForwarding) fb_snapshotForAttributeName:] + 656\n\t4   WebDriverAgentLib                   0x0000000106023878 -[XCUIElement(WebDriverAttributesForwarding) forwardingTargetForSelector:] + 220\n\t5   CoreFoundation                      0x00000001b6936454 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 123988\n\t6   CoreFoundation   ...
[14d0cad6][W3C] Matched W3C error code 'stale element reference' to StaleElementReferenceError
[14d0cad6][XCUITestDriver@f6d9] Encountered internal error running command: StaleElementReferenceError: The previously found element "Application 'cn.tinyapps.RST'" is not present in the current view anymore. Make sure the application UI has the expected state. Original error: Error getting main window kAXErrorServerNotFound
    at errorFromW3CJsonCode (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/node_modules/@appium/base-driver/lib/protocol/errors.js:1112:25)
    at ProxyRequestError.getActualError (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/node_modules/@appium/base-driver/lib/protocol/errors.js:981:14)
    at JWProxy.command (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:348:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at XCUITestDriver.proxyCommand (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:103:35)
    at XCUITestDriver.getWindowSizeNative (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/general.js:277:12)
    at XCUITestDriver.getWindowSize (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/general.js:52:14)
    at XCUITestDriver.getWindowRect (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/general.js:121:29)
[14d0cad6][HTTP] <-- GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/window/rect 404 2116 ms - 1795 
[14d0cad6][HTTP] --> GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/source {}
[14d0cad6][XCUITestDriver@f6d9] Calling AppiumDriver.getPageSource() with args: ["14d0cad6-8ef2-4a38-8807-b40b1a77170a"]
[14d0cad6][XCUITestDriver@f6d9] Executing command 'getPageSource'
[14d0cad6][XCUITestDriver@f6d9] Matched '/source?format=xml&scope=AppiumAUT' to command name 'getPageSource'
[14d0cad6][XCUITestDriver@f6d9] Proxying [GET /source?format=xml&scope=AppiumAUT] to [GET http://127.0.0.1:8100/session/57270DAE-310D-4CF2-A719-736F7C12430F/source?format=xml&scope=AppiumAUT] with no body
[14d0cad6][XCUITestDriver@f6d9] Got response with status 404: {"value":{"error":"stale element reference","message":"The previously found element \"Application 'cn.tinyapps.RST'\" is not present in the current view anymore. Make sure the application UI has the expected state. Original error: Error getting main window kAXErrorServerNotFound","traceback":"(\n\t0   CoreFoundation                      0x00000001b6921418 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 37912\n\t1   libobjc.A.dylib                     0x00000001afc01c28 objc_exception_throw + 56\n\t2   WebDriverAgentLib                   0x000000010602c820 -[XCUIElement(FBUtilities) fb_takeSnapshot] + 756\n\t3   WebDriverAgentLib                   0x000000010602ca64 -[XCUIElement(FBUtilities) fb_snapshotWithAttributes:maxDepth:] + 152\n\t4   WebDriverAgentLib                   0x0000000105fe4b00 +[FBXPath writeXmlWithRootElement:indexPath:elementStore:includedAttributes:writer:] + 708\n\t5   WebDriverAgentLib                   0x0000000105fe4274 +[FBXPath xmlRepresentationWithRootElement:writer:elementStore:query:ex...
[14d0cad6][W3C] Matched W3C error code 'stale element reference' to StaleElementReferenceError
[14d0cad6][XCUITestDriver@f6d9] Encountered internal error running command: StaleElementReferenceError: The previously found element "Application 'cn.tinyapps.RST'" is not present in the current view anymore. Make sure the application UI has the expected state. Original error: Error getting main window kAXErrorServerNotFound
    at errorFromW3CJsonCode (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/node_modules/@appium/base-driver/lib/protocol/errors.js:1112:25)
    at ProxyRequestError.getActualError (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/node_modules/@appium/base-driver/lib/protocol/errors.js:981:14)
    at JWProxy.command (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:348:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at XCUITestDriver.proxyCommand (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:103:35)
    at XCUITestDriver.mobileGetSource (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/source.js:50:35)
    at XCUITestDriver.getPageSource (/Users/suneel.subramanya/.appium/node_modules/appium-xcuitest-driver/lib/commands/source.js:25:9)
[14d0cad6][HTTP] <-- GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/source 404 2125 ms - 1648 
[14d0cad6][HTTP] --> GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/timeouts {}
[14d0cad6][XCUITestDriver@f6d9] Calling AppiumDriver.getTimeouts() with args: ["14d0cad6-8ef2-4a38-8807-b40b1a77170a"]
[14d0cad6][XCUITestDriver@f6d9] Executing command 'getTimeouts'
[14d0cad6][XCUITestDriver@f6d9] Responding to client with driver.getTimeouts() result: {"command":3600000,"implicit":0}
[14d0cad6][HTTP] <-- GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/timeouts 200 1 ms - 42 
[14d0cad6][HTTP] --> GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/timeouts {}
[14d0cad6][XCUITestDriver@f6d9] Calling AppiumDriver.getTimeouts() with args: ["14d0cad6-8ef2-4a38-8807-b40b1a77170a"]
[14d0cad6][XCUITestDriver@f6d9] Executing command 'getTimeouts'
[14d0cad6][XCUITestDriver@f6d9] Responding to client with driver.getTimeouts() result: {"command":3600000,"implicit":0}
[14d0cad6][HTTP] <-- GET /session/14d0cad6-8ef2-4a38-8807-b40b1a77170a/timeouts 304 2 ms - - 

Code To reproduce issue

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.options.ios import XCUITestOptions
import time

# Set up XCUITestOptions
options = XCUITestOptions()
options.platform_name = 'iOS'
options.platform_version = '16.7.10'
options.device_name = 'iPhone 8'
options.udid = '<YOUR_DEVICE_UDID>'
options.bundle_id = 'cn.tinyapps.RST'
options.xcode_signing_id = 'iPhone Developer'
options.no_reset = True

# Start the Appium session
driver = webdriver.Remote('http://localhost:4723', options=options)
driver.activate_app('cn.tinyapps.RST')
driver.page_source # this would invoke the above error

# Close the Appium session
driver.quit()
KazuCocoa commented 2 weeks ago

What the result of page source when the error occurred?

It looks like... the error itself could come from XCTest framework / Accessibility stuff internal by iOS side: https://www.google.com/search?q=kAXErrorServerNotFound+XCUITest&sca_esv=81b62b241f3359c7&ei=tXwIZ7QR09bQ8Q-Gq_OpAg&ved=0ahUKEwj0v4OHlIWJAxVTKzQIHYbVPCUQ4dUDCA8&uact=5&oq=kAXErrorServerNotFound+XCUITest&gs_lp=Egxnd3Mtd2l6LXNlcnAiH2tBWEVycm9yU2VydmVyTm90Rm91bmQgWENVSVRlc3QyBRAhGKABMgUQIRigATIFECEYoAEyBRAhGKABMgUQIRigAUj0FVCAAVidFHABeACQAQCYAWugAa8GqgEDNy4yuAEDyAEA-AEBmAIJoALBBsICCBAAGIAEGKIEmAMAiAYBkgcDNS40oAfsHQ&sclient=gws-wiz-serp

mykola-mokhnach commented 2 weeks ago

I assume it is not possible to get the page source or interact with this app in any way. The above error usually indicates the app is not automatable and must be fixed.

suneel944 commented 1 week ago

ok its a jailbroken app and here is the link of the app which I was trying to automate and capture element locators in appium inspector which was futile and not helpful as I got the kAXErrorServerNotFound.

the inspector fails load the screen sanpshot to fetch the elements and also while automating using the code, the app gets launched using the bundle_id, and it will not come to foreground and stays in background and i need to force it come to foreground using the driver.activate_app('cn.tinyapps.RST') but the later actions fail to register with regards to element interaction with kAXErrorServerNotFound

ios jailbreaking app: https://palera.in/

App link: https://www.ios-repo-updates.com/repository/bigboss/package/cn.tinyapps.rst/

KazuCocoa commented 1 week ago

We haven't tested the jailbreak environment, so it could be environment-specific...?

The error itself could occur in vanilla XCTest https://stackoverflow.com/questions/58757558/xcode-11-xcuitest-failed-to-get-matching-snapshots-error-getting-main-window-ka https://discuss.bitrise.io/t/xcuitest-kaxerrorservernotfound/11338 Some googled links said it could depend on the iOS and app side stuff like if the OS could scan? the UI elements.

the app gets launched using the bundle_id, and it will not come to foreground and stays in background and i need to force it come to foreground using the driver.activate_app('cn.tinyapps.RST')

I'm wondering if something weird app state occurred at the initial launching time. Then, accessibility services behind OS had an issue to scan the elements etc.

Perhaps it would be nice to check the device log

Closing this issue itself as perhaps OS and app related rather than Appium itself. (feel free to keep posting comments)