I had come across this post around 6 months ago, and I happily made use of the discussion in my code, successfully. I was using the ((IOSDriver) driver).getContextHandles() looping logic given by snoopgr2 and checking whether (SupportsContextSwitching)driver).getContext().contains(“WEBVIEW”) is true which was working fine.
Suddenly, today, the line before retrieving the ContextHandles() is throwing the error
getWindowHandle()=>page-69C76D33-9B55-4A11-AA2D-808829F9855Corg.openqa.selenium.**UnsupportedCommandException**: The command 'GET /session/FBE0A449-3336-453C-AFB2-96ECB3A72296/context' was not found.
I checked xcode project WebDriverAgentRunner is running OK or not, which is positive.
I don’t know why it is throwing this exception just today.
Looping logic for only iOS
if(!((SupportsContextSwitching)driver).getContext().contains(“WEBVIEW”)) {// sometimes default WEBVIEW_xxxx.y happens
whileloop:
while (loopCount < 10) { // looping ONLY for ‘iOS’
System.out.println(“loopCount-”+loopCount);
Thread.sleep(10000);//sleep and hope, the driver pulls the webview context
Set allContexts = ((IOSDriver) driver).getContextHandles();//non duplicates
System.out.println("iOS allContexts = “+loopCount+”, “+allContexts);
for (String context : allContexts) {
if (context.contains(“WEBVIEW”)) {
System.out.println(“WEBVIEW was found in iOS allcontexts.”);
((IOSDriver) driver).context(context); // set
break whileloop; //break both loops
} // if
} // for
loopCount++;
} // while
System.out.println(“Current iOS Context=”+loopCount+”, "+((SupportsContextSwitching)driver).getContext());
}//if
I am at (latest) Mac OS: 15.3.1, Appium: 2.11.5, Mobile: 18.3.1 (latest), Appium Java-Client: 9.3.0, selenium-java: 4.25.0, JDK: 21
The same code in STG box, which was deployed a few weeks ago is producing the below system output to console
Diver instance=IOSDriver: Safari on IOS (695e527b-10f5-4d3b-a9b1-4a1a7cf5fd60)
Current Platform=iOS
((SupportsContextSwitching)driver).getContext()=WEBVIEW_18770.1
loopCount-1
iOS allContexts = 1, [NATIVE_APP]
loopCount-2
iOS allContexts = 2, [NATIVE_APP]
loopCount-3
iOS allContexts = 3, [NATIVE_APP]
loopCount-4
iOS allContexts = 4, [NATIVE_APP]
loopCount-5
iOS allContexts = 5, [NATIVE_APP]
loopCount-6
iOS allContexts = 6, [NATIVE_APP]
loopCount-7
iOS allContexts = 7, [NATIVE_APP]
loopCount-8
iOS allContexts = 8, [NATIVE_APP]
loopCount-9
iOS allContexts = 9, [NATIVE_APP]
Current iOS Context=10, WEBVIEW_18770.1
I don’t know why it is throwing this exception today.
Please help.