How to get the text which is displayed as the error message in the screenshot attached ? I could not inspect it.
I tried using the below selenium java code but it failed:
String ale=driver.switchTo().alert().getText();
System.out.println(ale);
The error message displayed is
Exception in thread "main" org.openqa.selenium.NoAlertPresentException:no such alert
How can I fix it ?

You can get the message and the state by using the JavascriptExecutor:
Note: You just need to provide the input WebElement for each input tag.
Code:
Screenshot: