Appium iOS Testing - Crash with invalid Element State


When running my Appium tests and even when inspecting the app under test with Appium inspector, the app always crashes at the same point. This behaviour does not occur when using my app without Appium. I am looking forward to your help!


  • Appium version (or git revision) that exhibits the issue: 1.20.2
  • Desktop OS/version used to run Appium: macOS Big Sur 11.2.1
  • Node.js version (unless using|exe): v15.5.1
  • Mobile platform/version under test: IOS 14.4
  • Simulator
  • Xcode 12.4
  • Desired Capabilities for the Inspector Session:
  "app": "",
  "automationName": "XCUITest",
  "deviceName": "iPhone SE (2nd generation)",
  "platformName": "iOS",
  "waitForQuiescence": false


[XCUITest] Executing command 'performTouch'
[XCUITest] Received the following touch action: tap(options={"x":187,"count":1,"y":637})
[WD Proxy] Proxying [POST /wda/touch/perform] to [POST] with body: {"actions":[{"action":"tap","options":{"x":187,"count":1,"y":637}}]}
[WD Proxy] Got response with status 200: {"value":null,"sessionId":"my-session-id-2"}
[W3C (8861c94f)] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/my-session-id/touch/perform 200 362 ms - 14
[HTTP] --> POST /wd/hub/session/my-session-id/timeouts
[HTTP] {"implicit":60000}
[W3C (8861c94f)] Calling AppiumDriver.timeouts() with args: [null,null,null,null,60000,"my-session-id"]
[XCUITest] Executing command 'timeouts'
[BaseDriver] W3C timeout argument: {"implicit":60000}}
[BaseDriver] Set implicit wait to 60000ms
[W3C (8861c94f)] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/my-session-id/timeouts 200 1 ms - 14
[HTTP] --> GET /wd/hub/session/my-session-id/context
[HTTP] {}
[W3C (8861c94f)] Calling AppiumDriver.getCurrentContext() with args: ["my-session-id"]
[XCUITest] Executing command 'getCurrentContext'
[W3C (8861c94f)] Responding to client with driver.getCurrentContext() result: "NATIVE_APP"
[HTTP] <-- GET /wd/hub/session/my-session-id/context 200 1 ms - 22
[HTTP] --> POST /wd/hub/session/my-session-id/element
[HTTP] {"using":"accessibility id","value":"auswählen"}
[W3C (8861c94f)] Calling AppiumDriver.findElement() with args: ["accessibility id","auswählen","my-session-id"]
[XCUITest] Executing command 'findElement'
[BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[BaseDriver] Waiting up to 60000 ms for condition
[WD Proxy] Matched '/element' to command name 'findElement'
[WD Proxy] Proxying [POST /element] to [POST] with body: {"using":"accessibility id","value":"auswählen"}
[WD Proxy] Got response with status 400: {"value":{"error":"invalid element state","message":"The application under test with bundle id 
'' is not running, possibly crashed","traceback":"(\n\t0   CoreFoundation                     
0x00007fff20421af6 __exceptionPreprocess + 242\n\t1   libobjc.A.dylib                     
0x00007fff20177e78 objc_exception_throw + 48\n\t2   CoreFoundation                     
0x00007fff20421797 -[NSException init] + 0\n\t3   WebDriverAgentLib                   
0x000000010d88183b -[FBSession activeApplication] + 667\n\t4   WebDriverAgentLib                  
0x000000010d883dfb +[FBFindElementCommands handleFindElement:] + 267\n\t5   WebDriverAgentLib                   
0x000000010d83f856 -[FBRoute_TargetAction mountRequest:intoResponse:] + 182\n\t6   WebDriverAgentLib                   
0x000000010d81aa88 __37-[FBWebServer registerRouteHandlers:]_block_invoke + 536\n\t7   WebDriverAgentLib                   
0x000000010d866a2b -[RoutingHTTPServer handleRoute:withRequest:respo...     // Comment by me: This really stops here.
[W3C] Matched W3C error code 'invalid element state' to InvalidElementStateError

It’s possible that Appium is running the app so fast that it’s exposing a race condition that you would rarely see when using the app manually.

Try enabling:

showIOSLog: true

in your capabilities and see if you can see why the app is crashing. If you can pinpoint it, probably would be good to show to developers at the very least, or open a bug to unblock automation. See here for more:

1 Like