0

I'm new to Android development and I am trying to make an app that will open a website and automatically set the username and password in the login form that appears.

Here is the code that I written to do this:

webView.loadUrl("http://www.bhos.edu.az/az/login?r=http://www.bhos.edu.az/az/page/67-imtahan-naticalari");
webView.getSettings().setDomStorageEnabled(true);

webView.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView view, String url) {
        String user = "Foundation";
        String pwd = "ZDxRvjS3";

        view.loadUrl("javascript:document.getElementsByName('username').value = '"+user+"';document.getElementsByName('passwd').value='"+pwd+"';");
    }
});

But when I run my app, I always see one of the values that I have set on a blank page, instead of the website.

Here's a screenshot of what I see:

The example of my result

How can I solve this?

Adrian Sanguineti
  • 2,455
  • 1
  • 27
  • 29
Tərlan Əhəd
  • 179
  • 3
  • 10
  • Try moving `webView.loadUrl("...")` after the other commands. You should open the URL *after* setting up the `webView`. You should also remove a live, working login from a public page like this. –  Jun 13 '17 at 14:34
  • Thanks very much,but it doesn't work,it is only the last bug of my app :)., – Tərlan Əhəd Jun 13 '17 at 15:23
  • 1
    Possible duplicate of [Android Calling JavaScript functions in WebView](https://stackoverflow.com/questions/4325639/android-calling-javascript-functions-in-webview) –  Jun 13 '17 at 16:35
  • I don't know JavaScript so much,if you could help me about this issue,i would be thankful to you :) – Tərlan Əhəd Jun 13 '17 at 17:55
  • Did you look at this answer? https://stackoverflow.com/a/31291128/5734311 –  Jun 13 '17 at 18:34

0 Answers0