title: How to enter username and password automatically in Webview
body: <p>I am creating an app to help me and other students log into our school's website quickly. The school website is <a href="https://my.gediz.edu.tr/" rel="nofollow">https://my.gediz.edu.tr/</a></p>
  
  <p>I created an application with a WebView the thing is I want that the webview enters username and password automatically so that the user is already logged in when he starts the application. I googled it and found something like that but it does not work.</p>
  
  <pre><code>import android.app.ActionBar;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity {
  
  TextView txtMsg;
  WebView webview;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      android.support.v7.app.ActionBar actionBar=getSupportActionBar();
  
      // ActionBar actionBar=getActionBar();
      actionBar.setLogo(R.drawable.ic_actionbar_gediz1);
      actionBar.setDisplayUseLogoEnabled(true);
      actionBar.setDisplayShowHomeEnabled(true);
  
      txtMsg=(TextView)findViewById(R.id.textView1);
      //webview=(WebView)findViewById(R.id.webview1);
      demo1TrySpecificURL();
  
      //zoom
      webview.getSettings().setBuiltInZoomControls(true);
  }
  
  private void demo1TrySpecificURL(){
      webview=(WebView)findViewById(R.id.webview1);
      webview.getSettings().setJavaScriptEnabled(true);
      //webview.setWebViewClient(new MyWebClient(txtMsg, "https://my.gediz.edu.tr/"));
      webview.loadUrl("https://my.gediz.edu.tr/");
  
      webview.setWebViewClient(new WebViewClient(){
  
          public void onPageFinished(WebView view, String url){
  
  
  
              view.loadUrl("javascript:document.getElementsByName('username')[0].value = 'username'");
              view.loadUrl("javascript:document.getElementsByName('password')[0].value = 'password'");
  
  
              view.loadUrl("javascript:document.forms['Login'].submit()");
          }
  
      });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      //return super.onCreateOptionsMenu(menu);
      getMenuInflater().inflate(R.menu.menu_main, menu);
  
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
  
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.forward_page) {
          webview.goForward();
          return true;
      }
  
      else if (id == R.id.back_page) {
          webview.goBack();
          return true;
      }
  
      else if (id == R.id.reLoad_page) {
          webview.reload();
          return true;
      }
  
      else if (id == R.id.zoom_in) {
          webview.zoomIn();
           return true;
      }
  
      else if (id == R.id.zoom_out) {
          webview.zoomOut();
          return true;
      }
  
  
  
      return super.onOptionsItemSelected(item);
  }
  
  public void blaHandler(View view) {
  
      webview.setWebViewClient(new WebViewClient(){
  
          public void onPageFinished(WebView view, String url){
  
              view.loadUrl("javascript:document.getElementsByName('username')[0].value = 'username'");
              view.loadUrl("javascript:document.getElementsByName('password')[0].value = 'userpassword'");
  
              view.loadUrl("javascript:document.forms['Login '].submit()");
          }
  
      });
  
  }
  }
  </code></pre>