When We Should Use KeyPress Instead of setText in Open Script??

May 19, 2015

Last week I was testing an application which was based on servlet and client validation was on some javascript most likely ajax.

A customer needed to fill up a form for signup.As usual it was having First name,Last name,Address,City,Country, Mobile No.

What I did ??
I tried to record the scenario. While recording OATS recorded all the text filed with setText() method. Script looked cool.

While playing back,It did fill up the form but application was throwing error. It was saying that all fields were mandatory and user needed to fill it.

I noticed there was a ajax call which was sensing the key press event and trying to read the record on focus change.So manually when I tried to reproduce the case,application was behaving correctly. I changed the setText() method to keyPress() method and instead of clicking on the next field. I pressed TAB key. It worked!!!!.

  • I general form fill up, When we click on submit button,all text filed data go to server. In this case we can use setText()
  • In a case where application directly does not read the user input via a submit button. Rather it reads on keyPress or keyUp[Nothing but a javascript (ajax call).]And process data accordingly. We must use keyPress()
  • There should not be any space in data inside keyPress() method. Like keyPress("Test1234") is valid but keyPress("Test 1234") is Invalid
  • setText does a copy paste operation. So in such places where copy paste is prohibited we must use keyPress.

You Might Also Like


  1. How can a random value coming from databank be used with keyPress?