Not able to switch native to web view in iOS?


I am not able to switch from native to web view in iOS application . I tried using below code it is not working not able to switch

Set contextHandles = driver.getContextHandles();

for (String s : contextHandles)


System.out.println(“content :”+ s);

if(s.contains(“WEBVIEW”)) {




can someone please help how switch from native to web view

always getting below error

Driver info: driver.version: AppiumDriver

at io.appium.java_client.AppiumDriver.getContextHandles(

at ZDebugTests.iOSTest.main(

Caused by: java.lang.ClassCastException:$TransformedEntriesMap cannot be cast to java.util.List

at io.appium.java_client.AppiumDriver.getContextHandles


huh… I have never seen getContextHandles spit out that error before… My best guess right now, since I cant see its definition, is that something is wrong with how you are setting the driver object… I could be incorrect here but it looks like you are making this an AppiumDriver which I think is supposed to be used more as an abstract template than it is a runtime object. Looking at my code, I define my driver as either IOSDriver or AndroidDriver which both inherit from AppiumDriver… Try defining your driver as an IOSDriver and see if that gets you better results… If not, Could you show me how you are building the driver and attach the Appium logs from your run?