Function onchange event doesn't work with automation
Hi... I have a keyword test for an application that is used for employees to enroll in healthcare. My company charges less for healthcare for an employee's spouse if the spouse is an employee also. There is a textbox where the user can input the spouse's employee number and it verifies that the spouse is indeed an employee. The validation occurs on an onchange event for this particular textbox:
TextBox:
function onchange(event)
{
javascript:setTimeout('__doPostBack(\'ctl00$BodyPlaceHolder$SpousalSurveyControl$SpouseEmployeeNumber\',\'\')', 0)
...
This onchange event works great... up until the time I run the automation. When the automation is running, this validation does not take place, and the test case comes to a halt. When the test is not running, and I manually test this, it works every time.
Can anybody tell me why this does not work when my keyword test is running or suggest an approach to make this work with the automation?
Thank you in advance for your help!
What step are you executing on the field in question? If you're using something like "SetText" or similar call, that is not going to trigger an "onchange" event. Usually, in my experience, those fire when a user actually clicks or tabs out of a field in order to register the actual change.
WorkAround #1: For the field that you know is going to trigger the onchange, once you've entered the data, actually call a "Click" or "Keys" function on the next field to trigger the event
WorkAround #2: Now, this worked for me on a desktop application, but you might be able to call Object.OnChange() directly within your test scripts. I'm not sure if this is available for a web application but it's something to investigate.
Either of these SHOULD trigger your onchange event.
Let me know if this helpsHow are you interacting with the textbox through TestComplete? Are you calling the SetText() method or the Keys() method when inputting text? If you are using SetText() try using the Keys() method instead as that should trigger the onchange event for the textbox.