[英]Fill fields in webview programmatically
I was trying to insert values into fields in a webpage loaded inside a webview.我试图将值插入到 webview 中加载的网页的字段中。
The exact thing i was doing was this -我正在做的确切事情是这个 -
String date = "5/8/1994";
webview.loadUrl("javascript:var uselessvar_a =document.getElementById('dpStudentdob_dateInput').value='" + date + "';");
Problem问题
the webpage is was loading is this .正在加载的网页是这个。
I want to enter the date into the date DOB field in the webpage.我想在网页的日期 DOB 字段中输入日期。
My full java class is-我的完整 java 类是-
public class MainActivity extends AppCompatActivity {
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDisplayZoomControls(false);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String password = "1201329022";
String date = "5/8/1994";
webview.loadUrl("javascript:var uselessvar =document.getElementById('txtRegNo').value='" + password + "';");
webview.loadUrl("javascript:var uselessvar_a =document.getElementById('dpStudentdob_dateInput').value='" + date + "';");
webview.loadUrl("javascript:var uselessvar_b =document.getElementById('btnView').click();");
}
});
webview.loadUrl("http://bputexam.in/StudentSection/ResultPublished/StudentResult.aspx");
}
}
Do any one have any suggestion for this.有没有人对此有任何建议。
To insert text inside an input text field in webview you have to use javascript like below:要在 webview 中的输入文本字段中插入文本,您必须使用如下的 javascript:
webView.loadUrl("javascript:(function(){l=document.getElementById('form1:txtDrname').value='" + editTextInput.getText().toString() + "';})()");
Then you can click a button inside webview to perform search:然后你可以点击 webview 中的一个按钮来执行搜索:
webView.loadUrl("javascript:(function(){l=document.getElementById('form1:btnSubmit');e=document.createEvent('HTMLEvents');e.initEvent('click',true,true);l.dispatchEvent(e);})()");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.