Setting Date in DatePicker/Calendar field - Entering text directly disabled

2 Answers 44 Views
Coded Steps Coded Tests Test Recording
Mark
Top achievements
Rank 1
Iron
Mark asked on 02 May 2025, 08:49 AM

I have numerous DatePicker fields which use a Calendar to set the Date. Date cannot be entered directlly in to the Text Box

Can anyone advise how i can set a date directly in this field. Have tried using a Set Text step but this just opens the Calendar

Is there some sort of Code i can write to set the Date? Also can the Date be set to a specific Date x amount of days from todays date?

Many Thanks

Elena
Telerik team
commented on 05 May 2025, 12:24 PM

Hi Mark, 

Our general recommendation is to use the input field and set the desired date that way because the calendar popup changes every month.

Of course, it should be still possible to automate that control where the input field cannot be used but it is very essential to know the exact structure of the datepicker control. Is it possible to share a sample page with the same calendar input and a possible scenario to automate? 

Regards,
Elena

Mark
Top achievements
Rank 1
Iron
commented on 06 May 2025, 10:50 AM | edited

Hi Elena

This is an internal page that is not available externally. Can you let me know if i can provide any further info that would help at all?

It looks as below and is used in various parts of the System

I've inspected the emelent and the details for this are as below

<input name="ctl00$ContentPlaceHolder1$TextBox_DecisionToTreatDate" type="text" id="TextBox_DecisionToTreatDate" class="date-picker required hasDatepicker" readonly="readonly">

 

Let me know

 

Mark
Top achievements
Rank 1
Iron
commented on 06 May 2025, 12:11 PM

Hi Elena

 

Can click the Contol to bring up the DatePicker am just stuk on how to then set the date once it is opened

Ideally i want to set the date to be x numbe of days in the future/past from todays date

Hope that makes sense

Elena
Telerik team
commented on 08 May 2025, 09:05 AM

Hi Mark, 

Test Studio interacts with the HTML elements listed in the DOM tree of the automated page. In the case when you can't set the date directly in the input - which is our recommendation indeed, you will need to explore the elements in the calendar popup in details in order to find the best approach for automating the current scenario. 

What you can check is what step gets recorded for the following actions:

  • When you select any date from the popup.
  • When you click any of the arrows to move a month back or forward.
  • When you try to verify which is the current month presented.

Once you have these steps you will need to explore the elements recorded for these and if their auto-generated find expressions are reliable for any next execution. For example, if the element uses TagIndex as identifie it will certainly not be reliable. So, you will need to adjust the find expression to use more meaningful attributes of the html element. 

Then when it comes to the requirement for setting a date which is x number of days in the future or in the past from todays date -  there is no out-of-the-box mechanism to tailor this up. However, you can use a coded step to get the desired date. This is one possible option but I don't have any specific recommendation because at this point there are a lot of missing pieces considering the above paragraphs. 

If you need further assistance I will need to explore the application further. Thus I will need either a public accessible page with the same control, or the DOM tree of the one you work on. 

If there is no page to share along, then collect the DOM tree as follows - see the image for reference on how to copy the DOM:

  1. One snippet of the DOM on the page before you open the calendar popup.
  2. One snippet of the DOM on ethe page while the calendar popup is opened.

I hope this information is of further help for you. 

Regards,
Elena

2 Answers, 1 is accepted

Sort by
0
Steven
Top achievements
Rank 2
Iron
Iron
answered on 02 May 2025, 11:54 AM

No sure if this helps, but here is code I wrote to check kids Birthday threshold boundaries.

 

 public class TestRegistrationStudentBirthdatesTest : BaseWebAiiTest
    {
        #region [ Dynamic Pages Reference ]

        private Pages _pages;

        /// <summary>
        /// Gets the Pages object that has references
        /// to all the elements, frames or regions
        /// in this project.
        /// </summary>
        public Pages Pages
        {
            get
            {
                if (_pages == null)
                {
                    _pages = new Pages(Manager.Current);
                }
                return _pages;
            }
        }

        #endregion
        
        // Add your test methods here...
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep()
        {
            // Enter Date value for 'DOBText' for P3 High Threshold 
            //Manager.Desktop.KeyBoard.TypeText("08/02/2019", 50, 100, true);
            Manager.Desktop.KeyBoard.TypeText("08/01/2021", 50, 100, true);  //for 2024-25
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep1()
        {
            // Enter Date value for 'DOBText' for P3 Low Threshold
            Manager.Desktop.KeyBoard.TypeText("08/02/2020", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep2()
        {
            // Enter Date value for 'DOBText' for P4 High Threshold
            Manager.Desktop.KeyBoard.TypeText("08/01/2020", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep3()
        {
            // Enter Date value for 'DOBText' for P4 Low Threshold
            Manager.Desktop.KeyBoard.TypeText("08/02/2019", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep4()
        {
            // Enter Date value for 'DOBText' for K Low Threshold
            Manager.Desktop.KeyBoard.TypeText("08/02/2017", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep5()
        {
            // Enter Date value for 'DOBText' for K High Threshold
            Manager.Desktop.KeyBoard.TypeText("08/01/2019", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep6()
        {
            // Enter Date value for 'DOBText' for 1-12 Low Threshold
            Manager.Desktop.KeyBoard.TypeText("08/02/2002", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep7()
        {
            // Enter Date value for 'DOBText' for 1-12 High Threshold
            Manager.Desktop.KeyBoard.TypeText("08/02/2018", 50, 100, true);
        }
    
        [CodedStep(@"New Coded Step")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep8()
        {
            // Enter Date value for 'DOBText' for P3, P4, 1-12 Complete Out of Bounds
            Manager.Desktop.KeyBoard.TypeText("08/01/2000", 50, 100, true);
        }
    
        [CodedStep(@"Verify 'InnerText' 'Contains' '[ - None - ]Pre-K 3 year oldPre-K 4 year oldKindergartenFirst GradeSecond GradeThird GradeFourth GradeFifth GradeSixth GradeSeventh GradeEighth GradeNinth GradeTenth GradeEleventh GradeTwelfth Grade' on 'GradeLevelSelect'")]
        public void TestRegistrationStudentBirthdatesTest_CodedStep9()
        {
            Manager.ActiveBrowser.RefreshDomTree();
            
            // Verify 'InnerText' 'Contains' '[ - None - ]Pre-K 3 year oldPre-K 4 year oldKindergartenFirst GradeSecond GradeThird GradeFourth GradeFifth GradeSixth GradeSeventh GradeEighth GradeNinth GradeTenth GradeEleventh GradeTwelfth Grade' on 'GradeLevelSelect'
            Pages.Registration.GradeLevelSelect.AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Contains, "[ - None - ]Pre-K 3 year oldPre-K 4 year oldKindergartenFirst GradeSecond GradeTh" +
                            "ird GradeFourth GradeFifth GradeSixth GradeSeventh GradeEighth GradeNinth GradeT" +
                            "enth GradeEleventh GradeTwelfth Grade");
            
        }
    }
0
Mark
Top achievements
Rank 1
Iron
answered on 07 May 2025, 04:02 PM

Have now got this resolved using 

 

   [CodedStep(@"Start Date'")]
        public void StartDate_CodedStep()
        {
// Number of days to add
int daysInFuture = 5; // adjust as needed

 

// Calculate the future date
DateTime futureDate = DateTime.Now.AddDays(daysInFuture);

 

// Format the date in UK format (dd/MM/yyyy)
string formattedDateUK = futureDate.ToString("dd/MM/yyyy");

 

// Set the value to the date input or date picker
Pages.IQemoOnlineChemotherapy2.TextBoxStartDateText.Text = formattedDateUK;
        }
    }
}

Tags
Coded Steps Coded Tests Test Recording
Asked by
Mark
Top achievements
Rank 1
Iron
Answers by
Steven
Top achievements
Rank 2
Iron
Iron
Mark
Top achievements
Rank 1
Iron
Share this question
or