Forum Discussion

nastester's avatar
nastester
Regular Contributor
2 years ago

Selecting a past or future date based on current date in calendar object

I am facing an issue where I want to be able to select a future (or past) date in a calendar date picker object:

 

The issue is when I select a date, it maps an object as the day (the 21st) so the test would potentially fail on future runs:

 

I can currently verify the current date by using this function: 

aqDateTime.AddTime(aqDateTime.Today(), 0, 0, 0, 0)

 

But I need a way to programmatically interact with this object and set the date x days ahead of whatever the current date is.

 

I used to be able to do this with via the wDate [Set] operation and use a code expression to set the date:

aqDateTime.AddTime(aqDateTime.Today(), -7, 0, 0, 0)

aqDateTime.Today()

 

It seems like the wDate function is deprecated for Use XPath and CSS selectors for web objects projects which is a shame because it used to work very well.

 

4 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I'm not sure what exact control you are using, but I have a similar 3rd party control. If I use the Object Spy tool, I can see the following properties (wText),

    I always enter the date directly into its field using SetText method. Depending on the control, it exposes Min and Max date ranges too.

     

    I also use formatting

     

    • nastester's avatar
      nastester
      Regular Contributor

      rraghvani 

       

      Looks like I don't have wText available for my calendar widget 

       

       

       

      When I try to use SetText method, I get an error:

       

      textbox.SetText(aqDateTime.AddTime(aqDateTime.Now(), 7, 0, 0, 0));

       

      Failed to enter text in the edit box, since it is read-only. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    UI controls that look similar may have underlying differences, like yours. With certain web UI controls, you have to study the behaviour - for example, using the method SetText may not work, but if you were to click on the control, so it becomes enabled. Then you might be able to use SetText.

     

    It also helps to use the Object Browser, so that you can see the entire objects that make up the UI control.

     

    Also, take note of the date format. You have "MM-DD-YYYY", whereas I use "DD MM YYYY". So you need to get the input correct. 

     

    This control has a date range. If I try to enter a date that's not within range, then I get a validation message appearing.