← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #141241]: How to count variable drop down menus on website

 

Question #141241 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/141241

    Status: Open => Answered

RaiMan proposed the following answer:
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.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.