title: How can I validate required input fields using Selenium
body: <p>I'm new in automation testing and have a task to implement the automation to Register Student using a given Registration Form. </p>
  
  <p>The scenario is letting me a little bit confused on how to validate the input field in the registration form. </p>
  
  <p>I mean, if I don't fill a required field, the browser will indicate that I must fill that field. </p>
  
  <p>Another thing is that I'm using a <code>for loop</code> for 2 students, where I want the first time to leave the input fields empty. After submit I have to see it was validated and then fill the empty input fields to submit it again (now with data inserted in the fields).</p>
  
  <p>I'm sharing my code and would appreciate any help.</p>
  
  <pre><code>public class Cartus {
  
      public static  void fill() throws InterruptedException {
  
          System.setProperty("webdriver.chrome.driver", "E:\\workspace\\chromeDriver\\chromeDriver.exe");
  
          ChromeDriver driver = new ChromeDriver();
  
          for(int i=0; i&lt;2; i++) {
  
              driver.get("http://qa-5.ls.vu/v2/landing-page/cartus/en");
              driver.findElement(By.xpath("/html/body/div[4]/div/form/div[1]/div")).click();
              driver.findElement(By.xpath("/html/body/div[4]/div/form/div[1]/div/select/option[2]")).click();
              driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[1]/input")).sendKeys(/*"sami"*/);
              driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[2]/input")).sendKeys(/*"Mohaname"*/);
  
              WebElement ele=driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/input"));/*.sendKeys("0221-1234567");*/
  
              String date = FastDateFormat.getInstance("yyyyMMddHHmmss").format(System.currentTimeMillis());
              Thread.sleep(1000);
              driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/input"))
                      .sendKeys(/*"aali_"+date+"@outlook.com"*/);
              driver.findElement(By.id("submitButton")).click();
  
              if(ele.getAttribute("value").isEmpty()){
                  driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[1]/input")).sendKeys("abcds");
              }
              if(ele.getAttribute("value").isEmpty()){
                  driver.findElement(By.xpath("/html/body/div[4]/div/form/div[2]/div[2]/input")).sendKeys("abcds");
              }
              if(ele.getAttribute("value").isEmpty()){
                  driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/input")).sendKeys("abcds");
              }
              if(ele.getAttribute("value").isEmpty()){
                  driver.findElement(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/input")).sendKeys("aali_"+date+"@outlook.com");
              }       
              System.out.println("Test case succesfully run");
          }
      }
  }
  </code></pre>
  
  <p>Thank you.</p>