The Selenium API does not support the direct required field. However, you can easily get the state and message using the JavaScript (Java) part:
JavascriptExecutor js = (JavascriptExecutor)driver; WebElement field = driver.findElement(By.name("email")); Boolean is_valid = (Boolean)js.executeScript("return arguments[0].checkValidity();", field); String message = (String)js.executeScript("return arguments[0].validationMessage;", field);
Note that you can also use getAttribute to get validationMessage , although this property:
String message = driver.findElement(By.name("email")).getAttribute("validationMessage");
source share