Careeroza
Submitting Forms
Three Ways to Submit
driver.findElement(By.id("login-btn")).click(); // 1. click the button (best: like a user)
driver.findElement(By.id("password")).sendKeys(Keys.ENTER); // 2. press Enter in a field
driver.findElement(By.id("email")).submit(); // 3. submit() on any element inside the <form>Note: submit() works only inside a real <form> and skips JavaScript click handlers on the button. Modern single-page apps often do not use a form, so prefer click().
Form Validation Messages
driver.findElement(By.id("login-btn")).click(); // both fields empty
WebElement email = driver.findElement(By.id("email"));
System.out.println(email.getDomProperty("validationMessage"));Example
The browser's built-in "required" message (Chrome):
Run EmptyLoginTest.main()Example output
Please fill out this field.