How do I test whats entered in the field without submitting the form

Hello Everyone,

I have one scenario where a phone number field should only accept numbers not characters. I am currently using this piece of code to

def phonestring = org.apache.commons.lang.RandomStringUtils.randomAlphanumeric(12)

WebUI.setText(findTestObject('Customer_Information_Page/Field_Phone'), phonestring)

Upon running the code the phonestring is something like j0WTrLlIMDSk which is automatically converted to 0 when j0WTrLlIMDSk is set on that field by the script.

I want to test if the website is showing correct data in the field and I would prefer to do it without submitting as there is no other page until order confirmation to verify the number that was entered.

Also If I can get help about how do I filter out numbers from the string that would be great.

Can you share what the HTML for the field (and any child elements) looks like before AND after a value is set?

Your best bet will be to use Regex to accomplish this. See this:


Before filling out the field.

After filling out the field

Hmmmm, no luck.

And one more screenshot of the field after the field loses focus? You can accomplish this by clicking away from the field, like in the whitespace next to it. What we’re looking for is if the DOM stores the value you’ve entered in any way before submitting the form.

I switched focus to city field and then hovered my mouse on the phone field the placeholder attribute got updated with the phone number entered.

I think I can use :

Hover mouse on the phone field
Get attribute value
then match the value to the one I will get from the string with only numbers.

Is this the correct way ?

Are you sure you need to hover over the field to get the attribute to change? If so, then you’ll have to work with that, yes. It would be much nicer if the value was there regardless of mouse position.

I tried the way you described above by shifting focus away from the phone field but I wasn’t able to see anywhere in DOM saying the phone number field entered.

But I just find out that If I change the focus to other field and then click back on the phone field than the placeholder attribute is showing 222-222-2222


Then the approach I would take is:

1.) Set the value for the field.
2.) Click elsewhere to shift focus away from the field.
3.) Click the field to focus it again.
4.) Grab the attribute value and compare.

1 Like

Thanks, I would do that.