Need help to manipulate Date picker

Asked by Atul Desai

Hi, I am try to automate an application where i have to select date from date widget(date picker). I went to several post but I am not able to achieve the goal.

I referred following script but couldn't understand what to calculate #refPoint , day_width, day_height

#day = (row, column) # row 0 ... 4, column 0 ... 7
#refPoint = <center of top left day position>
#clickPoint = refPoint.offset(row*day_width, column*day_height)

I am attaching an image where I have to select day 14 of the month.. Can you help me with understanding the above code with example..

Thanking you in Anticipation.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Atul Desai (atuld) said :
#1

Sorry I am not able to attach the image, from where can i attach the image?

Revision history for this message
RaiMan (raimund-hocke) said :
#2

put the image somewhere in the net and post the link.

Revision history for this message
Atul Desai (atuld) said :
#3
Revision history for this message
RaiMan (raimund-hocke) said :
#4

something like that

head = find("1400150215933.png")
picker = head.below(135) # height of picker area
# correction to get the correct picker area, if dimension of head image does not fit correctly
picker.x -= 1
picker.w += 2
picker.y += 0

picker.highlight(1)
prh = int(picker.h / 5) # row height
pcw = int(picker.w / 7) # colomn width

def pickerSlot(n): # get the slot in sequence 1 to 5*7 = 35
    if n < 1: n = 0
    if n > 35: n = 35
    row = int((n -1) / 7)
    col = (n-1) % 7
    return Region(picker.x + col * pcw, picker.y + row * prh, pcw, prh)

pickerSlot(1).highlight(1)
pickerSlot(7).highlight(1)
pickerSlot(8).highlight(1)
pickerSlot(17).highlight(1)
pickerSlot(35).highlight(1)

def pickerDay(n, off = 0): # get the day 1 to 31, off is the number of days of last month in 1st week
    if off < 0: off = 0
    if off > 7: off = 7
    return pickerSlot(n + off)

# Picker for May 2014 has 4 days of April in 1st week
pickerDay(15, 4).highlight(1)
pickerDay(31, 4).highlight(1)

here you can download a zip of the real script:
https://dl.dropboxusercontent.com/u/42895525/datepicker.sikuli.zip

To get something like the weekday of some date, we have the respective modules in Python (see https://docs.python.org/2.6/library/datatypes.html)

Revision history for this message
Atul Desai (atuld) said :
#5

Thank you Raiman, I will definitely try this solution and let you know in case of any concerns or queries.

Revision history for this message
Atul Desai (atuld) said :
#6

Hi Raiman,
Thanks for your help, it worked and I am able to select a date randomly (I made little changes in the code where I am passing a random value to pickerDay() method).

I have one more question here, can we calculate the 'off' value dynamically instead of passing it static in pickerDay(n, off=0) method.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

--- calculate the 'off' value dynamically
this exactly what I was too lazy to do :-)

and added the above hint:;
To get something like the weekday of some date, we have the respective modules in Python (see https://docs.python.org/2.6/library/datatypes.html)

you have to calculate the weekday of the 1st of a month and then you know the off value.

Revision history for this message
monicar (monicar) said :
#8

I am having the same issue, I am trying to select date from date time picker but I coud'nt (Flash Application)

Can I have code in Java please?

Can you help with this problem?

Provide an answer of your own, or ask Atul Desai for more information if necessary.

To post a message you must log in.