3

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.

alexward1230
  • 579
  • 3
  • 8
  • 25

1 Answers1

2

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();
  • By looking at the code at the search form, I noticed a behavior that explains the data loss. This should work for you if you are searching for Class Nbr 83998. Copy and paste it as a single line into your code (no need to split it up). I simply execute the same JavaScript code that is in the onChange after setting the value. `javascript: obj = document.getElementById('SSR_CLSRCH_WRK_CLASS_NBR$8'); obj.value = '83998'; addchg_win0(obj); doEdits_win0(obj,'S(5.0)','N','N','N','N','N','N',/^ *[0-9\,]*(\.[0-9\,]*)? *$/); document.getElementById('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH').click(); void(0)` – LiveLongAndProsper Nov 16 '14 at 01:52
  • Thank you so much! That worked! I am so happy couldn't have done that by myself. Whew time for pizza. Thanks man :) – alexward1230 Nov 16 '14 at 02:03
  • You're welcome - glad I could help. The solution was to set the value in the specific input-field then execute whatever was in the onChange event (removing the "return" keyword") for that particular field. If you decide to use the code on another field check the events on that field otherwise it might not work. Since only my second last comment was actually relevant I will delete the other comments. I suggest you do the same with your comments :-) – LiveLongAndProsper Nov 16 '14 at 02:14