I am currently working on a project to automate filling out an online login form using local string variables. This is the progress I have made so far:
web = (WebView) findViewById(R.id.webview);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
web.getSettings().setUserAgentString("Mozilla/5.0 " +
"(Windows NT 6.2; " +
"WOW64) AppleWebKit/537.31 " +
"(KHTML, like Gecko) Chrome/20 " +
"Safari/537.31");
web.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
web.loadUrl("http://ta.yrdsb.ca/yrdsb/");
web.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String username="test";
String password="test";
view.loadUrl("javascript:document.getElementById('username').value = '"+username+"';document.getElementById('password').value='"+password+"';");
}
});
The problem I am facing is that the fields are not getting filled in. I suspect the issue lies with the lack of id attributes for these text fields on the website. The username field looks like this (without an id):
<input type="text" name="username" size="10" border="0">
So my question is how can I accomplish this task without having access to the ids of the username and password fields? Am I overlooking something?
Thank you in advance.