code: public Page getAndSubmitLoginForm(HtmlPage loginPage, String username, String password) throws Exception {
          if (loginPage == null) {
              throw new Exception("Cannot submit login form because the provided HtmlPage object is null.");
          }
          HtmlForm form = getAndValidateLoginForm(loginPage);
          return fillAndSubmitCredentialForm(form, username, password);
      }
docs: Fills out the first form found in the provided login page with the specified credentials and submits the form. An exception
  is thrown if the provided login page does not have any forms, if the first form does not have an action of
  "j_security_check", or if the form is missing the appropriate username/password inputs or submit button.