Forum Discussion

DCat1223's avatar
DCat1223
Frequent Contributor
8 years ago
Solved

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 helps

  • How 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.

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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 helps

  • How 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.

    • DCat1223's avatar
      DCat1223
      Frequent Contributor

      Thank you so much tristaanogre and ghuff2!  That was it.  I was using SetText.  Such a simple solution that has been driving me crazy.  This user community is outstanding!  Can't thank you guys enough!

       

      Cheers!

       

      Dave.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        DCat1223:

        Hi Dave,

         

        What version of TestComplete are you using?

        The case is that SetText did not fire the OnChange event for version up to 11.30, but since 11.30 the event must be fired (see

        version history in the documentation). So if you are using version 11.30 and up, you may report this problem to Support.