Clearing a numeric or text field does not fire off validation message

I have numeric and text fields that when blank fire a message to let user know input is required. If I manually perform the test the message will appear, but when I use Selenium Library keywords to either “clear element text” or “input text” with an empty string the message will not fire.

In both of these examples, I am first tabbing to the field from a previous field and then invoking the keywords. The fields in the example have data in them. I notice the data in the fields get highlighted and then are removed. I do not know how the code removes the data (back button or delete) but I cannot replicate the issue of not having the message fired when I manually remove the data.

Examples:
input text //[@id=“amountInput”] \ clear=true
press keys //
[@id=“amountInput”] TAB

OR
clear element text //[@id=“amountInput”]
press keys //
[@id=“amountInput”] TAB

Message that would get fired
image

I have tested a few other options but the results were never 100%.

press keys //*[@id=“amountInput”] CTRL+A+BACKSPACE
page should contain Amount is required

OR

press keys //*[@id=“amountInput”] A+BACKSPACE
page should contain Amount is required

Same issue. Didi you find the way to make it work?

Depending on the event, try making a click away from the field. So pick a random element you can click to after clearing, you may find it triggers the event.

Thanks @_daryl
After several attemps with different keywords the only one that works in my webapp was:

press keys ${webitem} CTRL+A+BACKSPACE

This is typical issue with application not really written for testability - input validation is hooked into key press events only. Approach works for actual human but not for automation purposes.

4 Likes