2015-08-19 49 views
1

我想在混合iOS應用程序中獲得可用的上下文。然而,當我做如何在iOS應用程序中獲得可用的上下文

Set<String> text = ((IOSDriver) driver).getContextHandles(); 
    System.out.println(text); 

我得到以下錯誤:

org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.IOSDriver 

當我嘗試與創建AppiumDriver:

driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 

這是不允許創建AppiumDriver。如何在iOS應用程序中獲得可用的上下文。

回答

0

聲明驅動程序爲AppiumDriver類型。 使用此參考IOSDriver。然後它會工作。目前,似乎驅動程序變量是remotewebdriver的類型。

所以下面的代碼將工作

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是抽象的驅動程序,你可以作爲基類型參考使用實例化的驅動程序是否IOS或安卓

+0

感謝。我嘗試了你建議的代碼。但是,它仍然給了我同樣的錯誤。然後我改變了方法driver.getContextHandles(); to driver.getContext();此外,它僅返回了我的NATIVE_APP上下文,其中存在WebView中的應用程序。任何想法爲什麼第二種方法工作,爲什麼它不返回我的WEBVIEW。 – MKay

+0

您使用的是哪個版本的appium java客戶端? – Sham332

+0

我正在使用Java Client 2.1.0 appium版本1.4.8和iPad 8.1.3。 – MKay

相關問題