How to count variable drop down menus on website

Asked by Temporal Fusion

Hi,

I tried searching the reference and google
(I'm new to programming and Sikuli so excuse me if I'm overlooking something simple.)

What functions would work to 'count' the choices available in a drop down box on a website.
The website dropdown box can be variable and I'm trying to understand how to write a script to detect how many choices there are available and then loop my commands that many times.

Thanks much in advance.

Mac 10.6.6
Sikuli X-1.0rc1

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

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

This is one of the most challenging things, when using Sikuli - so be lionhearted on your way to a solution ;-)

lets make it multiple choice:

1. the box shows all lines when opened
2. the box needs scrolling to show all lines
please select an option

hopefully you selected 1., since this is a lot easier:

First (in any case) we have to restrict the region somehow to the area occupied by the menu. This could either be mesured by using e.g. the preview target offset, or somehow derived from other visual objects.

In such cases I always start with a selectRegion() to test my kernel features and then go back to substitute the selectRegion() with some intelligent find()s.

then if it is all text, we could use text() and count the lines. The grafics approach would be, to know the height of one line and then calculate the number of lines.

example using text and counting lines:
switchApp("Safari")
m = Region(0,0,999,22).find("Ablage") # 1st menu of Safari
r = m.left(1).right(250).below(310) # the measured area of the menu
click(m)
r.highlight(2) # this is our menu
menu = r.text().split(" \n ")[:-1]
for e in menu: print e
print "number of entries:", len(menu)

If you have chosen 2. above, it is far more complicated. The only feasible way I found until now is, to position on the first entry and use repeatedly type(key.DOWN) until you reach the end of the list, which can be checked, by capturing an image e.g. of the top x lines of the list, then Key.DOWN and again check with exists(img,0), wether it is the same (we reached the end) or has changed (still moving).

Hope it helps. Happy scripting.

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

if you are wondering about this:
menu = r.text().split(" \n ")[:-1]

look: bug 701005

Revision history for this message
Temporal Fusion (temporalfusion) said :
#3

Thanks Raiman, #1 should work for me if once I spend a bit more time understanding these new concepts, but I greatly appreciate your time and answer. And I will try my best.

Revision history for this message
Temporal Fusion (temporalfusion) said :
#4

Raiman,

Can you break down the line '.find("Ablage") # 1st menu of Safari' for me a bit.

Is Ablage literally what the 1st menu in Safari is actually called? I don't know what that word means or why I'd want to find the first menu in Safari, or if this is just an example and I'm missing the point of that step.

Sorry I'm so easily stumped. Thanks again

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

--- 1. yes it is an example how to read the "lines" of an opened menu

--- 2. yes it is the first menu entry in the top menu bar right beside "Safari" < apple-logo Safari Ablage ....>

Can you help with this problem?

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

To post a message you must log in.