Reputation: 589
I am making an app for myself to see when classes to my university (that are full) become available.
I need my app to be able to programmatically enter information into a 'class search' form and press the submit button so that I can check if any classes show up that 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 can enter in the data to the form and see it displayed in a webview. The problem is that when I have the program click the submit button nothing happens. Well, actually it does search however the previous data that I submitted gets lost and it searches with no values in the form.
This is my code so far:
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 I appreciate it. Website where the form is located above if you need to take a look at it as well.
Upvotes: 3
Views: 1117
Reputation: 359
I suspect that document.getElementsByName
is not supported. I suggest using document.getElementById
since the link (button) has an "id" attribute.
Instead of
document.getElementsByName('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH')[0].click();
:
Use:
document.getElementById('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH').click();
Upvotes: 2