javascript datetimepicker object and QTP
Question ID: 104609
0
0

Our developers have added a calendar object to our application. The calendar object is a javascript datetimepicker object (see http://trentrichardson.com/examples/timepicker). The calendar object is the usual calendar layout (click on a calendar day to select that date), plus it has a horizontal slider for the hour or the day and a horizontal slider for the minutes.

If you click in the slider trough for the hour slider, it jumps the time ahead by 3 hours (or behind by 3 hours, depends on where you click). You can also grab the slider handle and drag it to the desired hour.

The minutes slider is similar – click in the trough and it moves the minutes +-15 minutes in time. You can also grab the slider handle and drag it to the desired minute.

Once you’ve chosen a date and moved the sliders, you click on an OK button to apply the date/time changes in the app.

The problem is that I have no idea how to proceed. The developer says that "all I have to do" is invoke the datetimepicker object via javascript and pass it parameters to set the hour, or minute, or day, etc.

I can locate the "datetimepicker" class in the web page via descriptive programming, but now what? I tried (from the watch window) "children(0).object.datetimepicker("hour:=12")" but QTP complained that "datetimepicker" wasn’t known.

Could I create an HTML string that contains javascript function and somehow execute it against this page using QTP maybe – like this:

document.write("")

(my syntax may be screwed up here, but at least you get the idea – I hope). I want to be able to just call the datetimepicker object, pass it the date and time info I want to use, and have it set that date/time without my having to drag slider handles, click on slider troughs, etc.

anyone run into this kind of crazy stuff before? I am at a loss as to how to proceed.

Marked as spam
Posted by (Questions: 6, Answers: 6)
Asked on September 19, 2012 8:01 pm
213 views
Answers (2)
1
Private answer

I have done the jscript execution before but ended up using drag and drop. Here is code I used with QTP 11 IE 8. This is slow in QTP 11 IE 9 Win 7 and I think there is a patch for it (QTP_00718?)



myDate=22
myHour=6

Function getMyTime(myobj, returnpart)
   myTime=myobj.GetROProperty(''outertext'')  '(''innertext'')
   print ''mytime '' & myTime
   myTimeArray=split(myTime,'':'')
   getMyTime= CInt(myTimeArray(returnpart-1)) 
End Function


 Browser(''MyBrowser'').Navigate ''http://trentrichardson.com/examples/timepicker/''
Browser(''MyBrowser'').Page(''Adding a Timepicker to'').Link(''Examples'').Click


Browser(''MyBrowser'').Page(''Adding a Timepicker to'').Link(''Basic Initializations'').Click
Browser(''MyBrowser'').Page(''Adding a Timepicker to'').WebEdit(''basic_example_1'').Click
wait 1
Browser(''MyBrowser'').Page(''Adding a Timepicker to'').Link(''name:=''& myDate).Click

Set myTimeObj=Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''Time'')
Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''WebElement'').Click

' get  X and Y of the Hour slider 
myX = Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''WebElement'').GetTOProperty(''abs_x'')
myY = Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''WebElement'').GetTOProperty(''abs_y'')

pointer=0
vHour=getMyTime(myTimeObj,1)

Do until  myHour<=vHour

	' need the click and the coordinates  to set focuse on object
   Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''WebElement'').Click 10,10
   myMvX=myX
   myMvY=myY
   Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''WebElement'').Drag myMvX, myMvY, micLeftBtn
   pointer=pointer+2
    myMvX=myX+pointer
    myMvY=myY
    Browser(''MyBrowser'').Page(''Adding a Timepicker to_2'').WebElement(''WebElement'').Drop myMvX, myMvY
	vHour=getMyTime(myTimeObj,1)
	print vHour
Loop
Marked as spam
Posted by (Questions: 2, Answers: 98)
Answered on September 20, 2012 4:02 pm
1
Private answer

Also can you not just set the
WebEdit(''basic_example_1'').Set ''09/22/2012 03:14''

Marked as spam
Posted by (Questions: 2, Answers: 98)
Answered on September 20, 2012 4:33 pm
0
My ''DateTimePicker'' object is an HTML ''DIV'' tag and QTP can't do a ''Set'' on this kind of object - there's nothing to set. Buried several layers deeper under the ''DIV'' is a text field that displays the current date/time value, but that field is readonly. I tried sticking a value in it, but the value never changes. I'll explore your first post and see what I can do with that if I find I can't operate the javascript object via its methods. Your script looks like exactly what I would need if I were to do that. Thanks bubblehead!
( at September 21, 2012 12:49 pm)
0
Tim, Did you try the following? Browser(''MyBrowser'').Page(''Adding a Timepicker to'').WebEdit(''basic_example_1'').Set ''09/22/2012 03:14'' Browser(''MyBrowser'').Page(''Adding a Timepicker to'').WebEdit(''basic_example_1'').Submit
( at September 21, 2012 3:31 pm)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top