Forum Discussion

tomknapp1's avatar
tomknapp1
Senior Member
6 years ago

Javascript call to date picker function

I'm new to TestComplete.  I'm learning Javascript to address issues when TC cannot address certain objects.  I have a problem trying to input a date into a field.  The field will not accept manual input.  SetText and Keys do not work.  You have to use the date picker to populate the field, but TC cannot map the object (very strange).  The object uses a angular js to launch the calendar.  I've search the google-verse and cannot find a solution. Everything suggestion I have tried through javascript has failed (mostly Javascript Runtime errors).  I would have liked to provided html codes samples, but the environment is in a VM and security disallows copy/paste between environments.

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    While this might not work in your specific case, but it worked for me in many cases.

    -- Enter manually some date into the field;

    -- Locate the field using Object Spy and investigate it in the Object Browser. Your goal is a property that contains entered date. (Usually it is named as 'value'.)

     

    Now in test code you should do the following:

    -- Locate the field and assign required date value to the found property (e.g. <control>.value = '31/01/2019');

    -- Click the control or press Alt-Down or perform any other action that will open date picker control;

    -- When opened, the date picker control usually has the entered date pre-selected;

    -- Press Enter key to confirm date selection in the picker. This should trigger internal page code that will do all required actions/assignments/etc.;

    -- After the above sequence the control usually contains entered value that is correctly recognized and processed by page script code.

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    What other properties/methods are available?  Anything like a wText or wDate?  Anything like a "set date"?

    What I've had to do in the past is create a wrapper function to allow me to interact with similar components... It would be like "setCalendarDate" where it would take the component and the desired date as parameters and then go through some native objects and methods to perform the action.