Submit form data programmatically android (data lost)
I am creating an app for myself to see when classes at my university become available (which are complete).
I need my application to be able to programmatically enter information into the class search form and hit the submit button so that I can check if any classes are open.
Here is the website of the form: https://css.nevada.unr.edu/psc/rncssprd/EMPLOYEE/HRMS/c/COMMUNITY_ACCESS.CLASS_SEARCH.GBL
So far, I was able to enter data into the form and see it in the webview. The problem is that when I have a program, press the submit button, nothing happens. Well, it actually does a search, however the previous data that I submitted is lost and it searches without any values ββin the form.
This is my code:
public class Main extends Activity{
String URL = "https://css.nevada.unr.edu/psc/rncssprd/EMPLOYEE/HRMS/c/COMMUNITY_ACCESS.CLASS_SEARCH.GBL";
WebView mWebview;
int noRepeat = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
new FetchItemsTask().execute();
}
private class FetchItemsTask extends AsyncTask<Void,Void,Boolean> {
@Override
protected void onPreExecute() {
}
@Override
protected Boolean doInBackground(Void... params) {
// TODO Auto-generated method stub
return true;
}
@Override
protected void onPostExecute(Boolean result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
mWebview = (WebView ) findViewById(R.id.webView1);
// load login url
mWebview.loadUrl(URL);
//mWebview.setVisibility(View.INVISIBLE);
mWebview.getSettings().setJavaScriptEnabled(true);
mWebview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// first time go to search page
Toast.makeText(getApplicationContext(), "done loading login, pressing button", Toast.LENGTH_SHORT).show();
mWebview.loadUrl("javascript: {" + "document.getElementById('SSR_CLSRCH_WRK_SUBJECT$0').value = '"+"temp1"+"';" +
"document.getElementById('SSR_CLSRCH_WRK_CATALOG_NBR$1').value = '"+"temp2"+"';" +
"document.getElementsByName('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH')[0].click();" +
"};" ); // if I take out the click here the form will have temp1 and temp2 entered and everything fine, but it clicks temp1 and temp2 get cleared before it clicks some reason
}
});
}
}
Thanks for any help that I appreciate. The website where the form is located above in case you need to take a look at it as well.
source to share
I suspect document.getElementsByName
not supported. I suggest using document.getElementById
because the link (button) has an "id" attribute.
Instead
document.getElementsByName('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH')[0].click();
:
Using:
document.getElementById('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH').click();
source to share