Form Field Validation

Question ID: 105630

We have a web page that displays a message when a field has invalid data in it, and we need to validate that the correct message is being displayed. Sample HTML code is:


How do I validate that the proper message is displayed?

Marked as spam
Posted by (Questions: 339, Answers: 20)
Asked on October 23, 2014 6:30 pm
Answers (2)
Private answer

This is an HTML 5 feature and is not natively supported by UFT. You can't do any checkpoints on it because it is not persistent and goes away immediately upon losing focus. However, there is a way around it:

1. Open the object repository and highlight Test Objects in the left pane.
2. Click the Define New Test Object icon.
3. Set the following properties:
Environment: Web
Class: Page
Name: Whatever you want. For this example, we'll call it Validator
4. Click Add.
5. Click the Validator object in the object tree.
6. Change the Ordinal Identifier to Type:Index, Value:0
7. With the Validator page still highlighted, click the Define New Test Object icon again.
8. Set the following properties (Delete any other properties):
Environment: Web
Class: WebElement
Name: Whatever you want. For this example, we'll call it Validation
html tag: DIV
html id: contentContainer
9. Click Add.
10. In your test, do whatever causes the validation message to appear.
11. Use the following code to grab the text of the validation message:

strMessage = Page(''Validator'').WebElement(''Validation'').GetROProperty(''innertext'')

Now you can validate that strMessage contains the text you expect.

Marked as spam
Posted by (Questions: 16, Answers: 749)
Answered on October 23, 2014 6:31 pm
That's so awesome!
( at October 23, 2014 6:32 pm)
Private answer

You could also use descriptive programming to get the object.

 strMessage = Page(''index:=0'').WebElement(''html tag:=DIV'', ''html id:contentContainer'').GetROProperty(''innertext'')

Marked as spam
Posted by (Questions: 2, Answers: 98)
Answered on October 23, 2014 6:39 pm