问题一: self.driver.contexts只有NATIVE_APP没有WebView
解决方案: 1、需要开发开启webview远程调试功能.修改Activity extends CordovaActivity,设置setWebContentsDebuggingEnabled(true)
public class MyActivity extends CordovaActivity {
CordovaWebView cwv;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
this.appView.setWebContentsDebuggingEnabled(true);
}
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
}
再次获取contexts:
>>> driver.contexts
['NATIVE_APP', 'WEBVIEW_com.sxxxxx.xxx']
问题二:获取到Webview,但无法切换
查看报错信息:
error: Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Chrome version must be >= 43.0.2357.0
> (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64))
解决方案1:
根据报错信息要求的版本,下载更新手机的Android System WebView;
解决方案2:
下载更新版本的chromdriver替换: https://sites.google.com/a/chromium.org/chromedriver/downloads
C:\Users\zhouwanghua\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win