Forum Discussion

nastester's avatar
nastester
Regular Contributor
2 years ago

Interacting with datepicker object

Is there any way for me to interact with this object? 
I want to be able to set a future date but I keep getting  "Failed to enter text in the edit box, since it is read-only"

 

var end = Aliases.browser.pageMdaDashboard.formMarqueeupdatesform.textboxEndDate;
Log.Message(end);

end.Click();
end.SetText('07-18-2023')

 

Is SetText not the right method? What am I missing here?

 

 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What I had in mind, is to try and use Getting CSS Attributes, modify the attribute so that it's not read-only, enter the date, then change the field to read-only.

     

    It's a bit of a hack, since you are changing the web page. 

    • nastester's avatar
      nastester
      Regular Contributor

      Hmm yeah thats not an ideal solution but may be what I have to do. Will look into it, thanks

  • MW_Didata's avatar
    MW_Didata
    Regular Contributor

    If it's read-only then I dont think you can change it, otherwise I just use 'Keys'.

    For our software when days < 10 then i add a "0" before entering days

    SetText forces the text to change which might not be the greatest way t set someting like a date

    • nastester's avatar
      nastester
      Regular Contributor

      No unfortunately.  Just with button selections/drop downs

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    These properties, usually indicate that the control is enabled

     

    Are you able to manually enter '07-18-2023' in the text field box?

     

     

    • nastester's avatar
      nastester
      Regular Contributor

      No I can't.  It's read-only it seems 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What about when the date picker dialog appears, can you manually enter the date in the text field box?

     

    - I'm just trying to understand the behaviour, hence the questions. 

    • nastester's avatar
      nastester
      Regular Contributor

      rraghvani 

      No I can't at all. The only way to set the date is using the buttons...

       

      So I can do things like this: 

      Sys.Browser().Page(url).FindElement("//a[.='19']").Click();

       

      But this won't always work..

    • nastester's avatar
      nastester
      Regular Contributor

      The problem with that is repeatability of the test.  If I select July 25, it maps the '25' button and that won't always work (could be greyed out or a date in the past, etc)

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    A date picker control allows the user to select valid input dates for the application to accept.

     

    If a user is allowed to pick any date from the date picker, and then a validation message is shown for incorrect input. Then the control is not developed correctly.

    • nastester's avatar
      nastester
      Regular Contributor

      What I mean is if I manually interact with the datepicker, I am selecting the days as buttons..

      Past days after a certain point are not selectable (as are some future days in some cases).  If I create my test using one day, it may be greyed out and not selectable the next day thus causing the test to fail.. that is my issue with just interacting with the datepicker directly 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The selectable date range is changing based on todays date? It's the 25th today, and the options you can select is past 7 days from day. 

     

    You can use JavaScript - Working With Date Values, and calculate past 7 days from today, and click on the appropriate date. No matter when you decide to run your test, you don't have to modify your test, and it will select the appropriate date.