@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.loadUrl("http://www.baidu.com");
webview.setWebViewClient(new webViewClient());
}
需要开发在测试的程序里,打开 debug 模式。
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
}
Thread.sleep(5000);
driver.context("WEBVIEW_com.example.webviewapp");//根据print内容,填写你要测试context的名称
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('index-kw').value='111'");
driver.findElementById("index-bn").click();
Thread.sleep(10000);
driver.context("NATIVE_APP");
测试程序可以这样写。