Error in Appium Desktop refreshing source after adding snapshotMaxDepth greater than 62

When using the Appium Desktop inspector on iOS, I get the following error when refreshing the source after adding { "snapshotMaxDepth":63 } to the session. Anything greater than 62 results in this error.

[info] e[35m[HTTP]e[39m e[37m<-- POST /wd/hub/session/bb6bd6b0-f146-44e1-b241-e5094317efac/execute e[39me[32m200e[39m e[90m9615 ms - 93e[39m
[info] e[35m[HTTP]e[39m e[90me[39m
[info] e[35m[HTTP]e[39m e[37m-->e[39m e[37mGETe[39m e[37m/wd/hub/session/bb6bd6b0-f146-44e1-b241-e5094317efac/sourcee[39m
[info] e[35m[HTTP]e[39m e[90m{}e[39m
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m Calling AppiumDriver.getPageSource() with args: ["bb6bd6b0-f146-44e1-b241-e5094317efac"]
[debug] e[35m[XCUITest]e[39m Executing command 'getPageSource'
[debug] e[35m[WD Proxy]e[39m Matched '/source' to command name 'getPageSource'
[debug] e[35m[WD Proxy]e[39m Proxying [GET /source] to [GET http://127.0.0.1:8100/session/C122FCAD-BA5F-4150-9D86-838D6C222EBA/source] with no body[info] e[35m[WD Proxy]e[39m Got response with status 404: {"value":{"error":"stale element reference","message":"The previously found element \"Application 'com.boomin.customer'\" is not present in the current view anymore. Make sure the application UI has the expected state. Original error: Error kAXErrorIllegalArgument getting snapshot for element <AXUIElementRef 0x1584061d0> {pid=11089} {uid=[ID:1 hash:0x0]}","traceback":"(\n\t0   CoreFoundation                      0x000000010d8ddfba __exceptionPreprocess + 242\n\t1   libobjc.A.dylib                     0x000000010d787ff5 objc_exception_throw + 48\n\t2   WebDriverAgentLib                   0x0000000133f61e45 -[XCUIElement(FBUtilities) fb_takeSnapshot] + 1077\n\t3   WebDriverAgentLib                   0x0000000133f620fb -[XCUIElement(FBUtilities) fb_snapshotWithAttributes:maxDepth:] + 187\n\t4   WebDriverAgentLib                   0x0000000133eff6a9 +[FBXPath writeXmlWithRootElement:indexPath:elementStore:includedAttributes:writer:] + 937\n\t5   WebDriverAgentLib                   0x0000000133efe9d9 +[FBXPath ...
[debug] e[35m[W3C]e[39m Matched W3C error code 'stale element reference' to StaleElementReferenceError
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m Encountered internal error running command: StaleElementReferenceError: The previously found element "Application 'com.boomin.customer'" is not present in the current view anymore. Make sure the application UI has the expected state. Original error: Error kAXErrorIllegalArgument getting snapshot for element <AXUIElementRef 0x1584061d0> {pid=11089} {uid=[ID:1 hash:0x0]}
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m     at errorFromW3CJsonCode (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m     at ProxyRequestError.getActualError (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m     at JWProxy.command (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m     at runMicrotasks (<anonymous>)
[debug] e[35m[MJSONWP (bb6bd6b0)]e[39m     at processTicksAndRejections (internal/process/task_queues.js:85:5)
[info] e[35m[HTTP]e[39m e[37m<-- GET /wd/hub/session/bb6bd6b0-f146-44e1-b241-e5094317efac/source e[39me[31m500e[39m e[90m86 ms - 388e[39m

Prior to adding this setting, I can navigate round my app and refresh the source without any errors. After adding the setting, I get the same error everytime I attempt to move to a different page in the app and refresh the source.

Iā€™ve tried a direct api call to /appium/settings instead of using the GUI and I get the same problem. Iā€™ve also tried adding ā€œcustomSnapshotTimeoutā€ and a few other settings but nothing helps.

Itā€™s a react native .app file created with expo. Iā€™ve tested with a fresh react native expo app and it doesnā€™t have this problem. My capabilities are as followsā€¦

{
  "platformName": "iOS",
  "deviceName": "iPhone 12 Pro Max",
  "app": "/Users/matthewoconnor/Downloads/Boomin.app",
  "automationName": "XCUITest"
}

I canā€™t share the app file publicly but can share it privately if it looks like there might be a genuine bug that can be investigated.

1 Like

@Konnor5092 Did u get any solution for this issue.
I am facing same issue on iOS build (reactNative project) - getting StaleElementReferenceError on refreshing the screenshot if snapshotMaxDepth > 62

Hi :wave:

We started running into this problem as well. Late last week some elements that we were interacting with fell deeper into the DOM and we are unable to see them with the default "snapshotMaxDepth": 50 so we tried to bump it up to "snapshotMaxDepth": 70 and noticed we get a StaleElementReferenceError.

Details:
Appium Inspector: 22.2.1
iOS simulator: iOS 15
React native app.

This issue persists in Appium 2.1.3 with [email protected] in 2023. Have you found a solution to this problem?

When snapshotMaxDepth is left at its default value (50), I am unable to locate the necessary element because itā€™s insufficient for my test app. However, if I increase snapshotMaxDepth beyond 62, Appium hangs with a ā€˜stale element referenceā€™ error, leading to a StaleElementReferenceError.

same issue here!
Any solution?