Forum Discussion

kevin_kapell's avatar
kevin_kapell
Frequent Contributor
9 years ago

How can I make selections in the Xdsoft DateTimePicker?

How can I make selections in the Xdsoft DateTimePicker? Our code uses this picker and I cannot seem to code TestComplete Scripts correctly to pick a specific date. An example of this input field can...
  • Colin_McCrae's avatar
    Colin_McCrae
    9 years ago

    I'm not seeing the problem?

     

    I had a quick go at the example one you provided. Two quick hack-together solutions. All using C# Script I'm afraid as that's what my current project is using. Should be simple enough to convert.

     

    First one. Assigns the Picker text field to an object. Uses SetText to empty it. Then uses Keys + Tab out to set the new value. So as if the user typed it. Works fine for me.

     

      var Picker_Field = Sys["Browser"]("chrome")["Page"]("http://xdsoft.net/jqplugins/datetimepicker/")["Panel"](2)["Panel"](0)["Panel"](0)["Panel"](0)["Panel"](0)["Panel"]("main")["Panel"]("maininner")["Section"]("content")["Panel"]("system")["Article"](0)["Panel"](0)["Textbox"]("datetimepicker");
      
      Picker_Field["SetText"]("");
      Picker_Field["Keys"]("2016/12/25 11:11[Tab]");
    
      Runner["Stop"]();
      

     

    Second one. Uses the two back/forward buttons either side of month/year to cycle through 12 months until it gets a match. Then logs if it found a match or not. Has to click a day for the value to be retained by the text field so I have a day cell hard-coded in. If I wanted to do full automated control of it, I'd have to search the cell objects (use a Find method or whatever) to find the correct one, but you get the idea. Again, works fine for me. It clicks until it finds "December" (the value I've set it to search for), clicks a Day cell. Value is retained in the text field.

     

    If you were having problems only trying to change the month, that's probably because the text field doesn't retain the value if you ONLY cycle through the months. The value is retained when you click on a date cell in the table below. Try it manually. Same thing. It won't retain unless you click an actual Date.

     

     var Month_Back = Sys["Browser"]("chrome")["Page"]("http://xdsoft.net/jqplugins/datetimepicker/")["Panel"](11)["Panel"](0)["Panel"](0)["Button"](0);
      var Month_Forward = Sys["Browser"]("chrome")["Page"]("http://xdsoft.net/jqplugins/datetimepicker/")["Panel"](11)["Panel"](0)["Panel"](0)["Button"](2);
      var Current_Month = Sys["Browser"]("chrome")["Page"]("http://xdsoft.net/jqplugins/datetimepicker/")["Panel"](11)["Panel"](0)["Panel"](0)["Panel"](0)["TextNode"](0);
      var Day_Cell = Sys["Browser"]("chrome")["Page"]("http://xdsoft.net/jqplugins/datetimepicker/")["Panel"](11)["Panel"](0)["Panel"](1)["Table"](0)["Cell"](2, 3); 
      
      var Desired_Month = "December";
      
      var Month_Match = false;
      var Month_Text = "";
      
      for(var Month_Loop = 1; Month_Loop < 13; Month_Loop++) {
        Current_Month["Refresh"]();
        Month_Text = Current_Month["contentText"];
        if(Month_Text == Desired_Month) {
          Log["Message"]("Month found!");
          Month_Loop = 13;
          Month_Match = true;
        } else {
          Month_Forward["Click"]();
        }
      }
      
      if(!Month_Match) {
        Log["Message"]("Month not found ... :(");
      } else {
        Day_Cell["Click"]();
      }
    
      Runner["Stop"]();

     

    Normally, I wouldn't hard code all the values and object ref's, but this is a quick knock together example.

     

    So I'm not sure where you're hitting problems. (Should probably add, I'm using TC11.30 and Chrome)