trying to automate selecting date on a calendar on a webpage

Asked by dude

I'm currently parsing a date with originally looks like this:
End Date: 12/04/14(mm/dd/yy)

then i parse it so i have the values

endday = time.strftime('%d', rawdate)
endmth = time.strftime('%m', rawdate)
endyr = time.strftime('%Y', raw date)

The calendar looks like this:
http://postimg.org/image/dz1y81ijh/

Then first selecting the months I'm doing something like this at least for the months:
i use key.home to go to the top then use a if statement

if endmth.startswith("01"):
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
elif endmth.startswith("02"):
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
    type(Key.UP)
elif endmth.startswith("03"):

So far that works for months and I assume it would work for years but the years menu goes from 1980 to 2020
So I imagine it will be too cumbersome for an if statement
I'm wondering if there's something I can do that's more elegant?

And as for selecting a date on the calendar I have no clue how I'm going to accomplish it because the only way is to click the day

Any help or suggestions or better yet examples is appreciated :-)

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
Eugene S (shragovich) said :
#1

What I would do in your situation is write a small auxiliary function that will get the number of times the "UP" button should be pressed as a parameter. Then you can just call that function with a single line.

It might look something like that:

def buttonPress(button,count):
 """Press any provided button for "count" times.
 """
 for num in range(1, count+1):
  type(button)

Then you can call it like that:
buttonPress(Key.UP, timesToPress)

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

Eugene's suggestion is ok for now. Version 1.1 will have a repeat shortcut.

For dropdown menues, you always should check, wether it accepts entering the text directly and positions at the respective entry.
So for the year drop down check this after having clicked open the menu:
type("2013")
type(Key.ENTER)

same goes for the month menu
type("June")
type(Key.ENTER)

The date/datetime modules have appropriate functions, to evaluate these items directly from your raw date.

As for the selection of the day: the day area is a regular square having 5 rows each 7 columns. So you once evaluate the geometrics of this area and then you can evaluate each click point easily:
# the area on your image is 228x118
# you somehow have to evaluate this are starting form a found visual (e.g. the header containing the day names)
days = Region(<to be evaluated>)
dw = 118/5
dh = 228/5
dayOne = days.topLeft().offset(dw/2, dh/2)

# e.g. day 18
day = 18
dx = day % 7
dy = day // 7

this works, where the 1st is a sunday.

In other cases you have to evaluate the offset using the date functions and add it:

day = 18 + offset (0 for Sunday and 6 for Saturday)
dx = day % 7
dy = day // 7

then simply:
click(dayOne.offset((dx-1)*dw, (dy-1)*dh)

an example for another calendar:
https://dl.dropboxusercontent.com/u/42895525/ddcalendar.sikuli.zip

Can you help with this problem?

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

To post a message you must log in.