Checking if form was actually submitted - Java/Selenium/TestNG
<p>I want to be able to check if a form is submitted and then if the form isn't submitted and an error message appears to print the error to the reporter log or logger.</p>

<p>My code is below for clicking a login button:please Check</p>

<pre><code>  WebElement  login = driver.findElement(By.id("dijit_form_Button_1_label")); 
  login button.
  if(login.isDisplayed()){

      login.click();

      Reporter.log("Login Form Submitted  | ");
      logger1.info("Submit Button Clicked");

  } else {
      Reporter.log("Login Failed  | ");
      Assert.fail("Login Failed - Check Data | ");       
  }
</code></pre>

<p>I'm passing in parameters to fill out the login form, I have set up one incorrect value in my data provider, however, when it gets to this bit of code the form is always submitted so if the data is correct the code runs fine and prints login form successful etc. </p>

<p>If the login form doesn't submit but is clicked so you are returned to the same login screen with an error, The else part of the code is never printed?</p>

<p>So I need to be able to click the button if the button is clicked but failed to login then print the else to the logger/reporter log.</p>

<p>How do I get the else part of the code to print if login does not happen?</p>