Reputation: 836
I am trying to get the available contexts in hybrid iOS app. However, when I do
Set<String> text = ((IOSDriver) driver).getContextHandles();
System.out.println(text);
I get below error:
org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.IOSDriver
When I try to create AppiumDriver with:
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
It is not allowing to create AppiumDriver. How to get available contexts in iOS app.
Upvotes: 1
Views: 1895
Reputation: 11
If you are using a real device you need to run ios-webkit-debug-proxy so inside your driver set the capability called webkitDebugProxyPor
" to the port you want, and also activate the capability called startIWDP
.
Make sure you have installed ios-webkit-debug-proxy, which is easily installed using brew install ios-webkit-debug-proxy
Once you have everything up and running you should be able to see the web context.
Upvotes: 1
Reputation: 2832
Declare driver as type AppiumDriver. Use this a reference for IOSDriver. Then it would work. At the moment, it seems driver variable is of type of remotewebdriver.
So following code will work
AppiumDriver driver;
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Set<String> text = ((IOSDriver) driver).getContextHandles();
System.out.println(text);
AppiumDriver is abstract driver which you can use as base type reference to instantiated driver whether IOS or Andriod
Upvotes: 0