How to get tooltip text for validation in Selenium?
Hey Tim,
This is a very interesting question
Since we come across such messages when filling out sign-up forms. A classic case is when an email address is accidentally added without the @
sign, and a validation message is shown in the form of a tooltip.
For verifying the validation message, you can use the validationMessage
property of the element.
A simple scenario could be creating an account on Register Account and submitting the form (when the email address is entered in an incorrect format).
As seen in the attached screenshot, I have used document.getElementById("input-email").validationMessage
to get the text of the validation message.
As far as Selenium automation is concerned, you need to use the validationMessage
property with the JavaScript executor (or execute_script
) in Selenium.
Feel free to check out this sample repo, which showcases the solution in Selenium Python.
Hope this demonstration helps