driver.getContextHandles doesn't return multiple handles using .exe but does with desktop

12%20AM

When calling contextNames = driver.getContextHandles() in my suite, debugger shows contextNames = [Native_App], however when using appium inspector in web/hybrid app mode, the same screen allows me to see both native and webview contexts, indicating that there is more than one context detected. I added a Thread.sleep before getContextHandles as I thought maybe the webview context wasn’t loaded yet, but that didn’t seem to work. Do I need to add something to capabilities so appium can actually detect the webview context?

This is on a real device, not a sim
Appium 1.22
iOS 15.3

Check https://github.com/appium/appium/issues/16481#issuecomment-1058149339

logs for context

[debug] [W3C (446d11dd)] Calling AppiumDriver.getContexts() with args: [“446d11dd-f650-4d5d-9486-99f9bf1137f6”]
[debug] [XCUITest] Executing command ‘getContexts’
[debug] [XCUITest] Getting list of available contexts
[debug] [XCUITest] Retrieving contexts and views
[debug] [XCUITest] Selecting by url: false
[RemoteDebugger] Remote Debugger version 8.13.2
[debug] [RemoteDebugger] useNewSafari --> false
[debug] [RemoteDebugger] Checking which communication style to use (non-Safari on platform version ‘15.3’)
[debug] [RemoteDebugger] Platform version equal or higher than ‘12.2’: true
[RemoteDebugger] Setting communication protocol: using Target-based communication
[debug] [RemoteDebugger] Sending connection key request
[debug] [RemoteDebugger] Sending ‘_rpc_reportIdentifier:’ message (id: 0): ‘setConnectionKey’
[debug] [RemoteDebugger] Sending to Web Inspector took 1ms
[debug] [RemoteDebugger] Sending connection key request
[debug] [RemoteDebugger] Sending ‘_rpc_reportIdentifier:’ message (id: 2): ‘setConnectionKey’
[debug] [RemoteDebugger] Sending to Web Inspector took 1ms
[debug] [RemoteDebugger] Selecting application
[debug] [RemoteDebugger] No applications currently connected.
[debug] [XCUITest] No web frames found.
[debug] [W3C (446d11dd)] Responding to client with driver.getContexts() result: [“NATIVE_APP”]
[HTTP] <-- GET /wd/hub/session/446d11dd-f650-4d5d-9486-99f9bf1137f6/contexts 200 131 ms - 24
[HTTP]
[NATIVE_APP]

:thinking: a 5x for loop was able to locate the webview…

for posterity
Set contextNames = null;
for (int i = 0; i < 5; i++) {
contextNames = driver.getContextHandles();
}

Was able to switch contexts, but now I’m getting the following error when sending keys to a WebElement textField both via .exe and Appium Inspector

org.openqa.selenium.InvalidElementStateException: Element is not currently interactable and may not be manipulated

@mykola-mokhnach any ideas? I know that’s a fairly generic error