Appium [求助]driver.switchTo().window("WEBVIEW");无法工作

rattlesnake · 2013年12月30日 · 最后由 ben 回复于 2014年02月10日 · 2108 次阅读

刚开始学习 Appium,想自己写个在 webview 里测试的用例,代码如下

WebDriver driver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app","D:\MobileAuto\apk\HybridApp.apk");
capabilities.setCapability("device","android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.4");
capabilities.setCapability(CapabilityType.PLATFORM, "windows");
capabilities.setCapability("app-package", "com.example.webview");
capabilities.setCapability("app-activity", ".WebViewActivity");
try {
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.switchTo().window("WEBVIEW");

当执行到 switchTo 语句的时候,appium 报错说该方法没有实现,是我哪儿做错了吗?HybridApp.apk 里只有一个 webview,这个 apk 启动之后就会加载http://www.baidu.com.

多谢!

共收到 3 条回复 时间 点赞

各位同学帮帮忙啊,或者谁给一个用 java 写的访问 webview 里元素的例子,多谢了!


//setup the web driver and launch the webview app.
  DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
  desiredCapabilities.setCapability("device", "iPhone Simulator");
  desiredCapabilities.setCapability("app", "/Users/Apple/code/SafariLauncher/build/Debug-iphoneos/SafariLauncher.app");  
  URL url = new URL("http://127.0.0.1:4723/wd/hub");
  RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities);

  Thread.sleep(10000);
  //switch to the latest web view
  for(String winHandle : remoteWebDriver.getWindowHandles()){
    remoteWebDriver.switchTo().window(winHandle);
  }

  remoteWebDriver.get("http://saucelabs.com/test/guinea-pig");
  //Interact with the elements on the guinea-pig page using id.
  WebElement div = remoteWebDriver.findElement(By.id("i_am_an_id"));
  remoteWebDriver.findElement(By.id("comments")).sendKeys("My comment"); //populate the comments field by id.

  //leave the webview to go back to native app.
  remoteWebDriver.executeScript("mobile: leaveWebView");      

  //close the app.
  remoteWebDriver.quit();

加个头像~

请问这个问题解决了么?
我现在一直卡在这个问题上了。。。

info: Responding to client with success: {"status":0,"value":{"platform":"WINDOWS","browserN
ame":"","version":"4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled"
:true,"databaseEnabled":false,"app-package":"com.paic.mobileoa","device":"Android","app-acti
vity":".LoadingActivity"},"sessionId":"48a55fd2-d6f6-4f5d-b225-1567b1c402bd"}
GET /wd/hub/session/48a55fd2-d6f6-4f5d-b225-1567b1c402bd 200 4ms - 388b
debug: Appium request initiated at /wd/hub/session/48a55fd2-d6f6-4f5d-b225-1567b1c402bd/wind
ow
debug: Request received with params: {"name":"WEBVIEW"}
info: Responding to client that a method is not implemented
POST /wd/hub/session/48a55fd2-d6f6-4f5d-b225-1567b1c402bd/window 501 8ms - 180b
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册