← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #211517]: Combo box scrolling

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Oh yes, this is one of the most challenging things with Sikuli.

If you want to have a chance, to get it working visually (hence without
"reading" the menu entries textually - seems to be the case her), the
combo box (or any other menu like box, that can be went through using
the direction keys DOWN/UP).

In your case I understand, that you have the following type of box:
- text field contains a current value from a list
- on click this list is displayed below the field 
- the currently selected entry is highlighted and positioned
- the box does not show all entries at once

The goal:
select a specific entry based on the knowledge of the list content (number of entries and their sequence)

The approach:
position on the first entry and key down to the specific entry

The challenge:
make sure we position on the first entry in the list, no matter, where the current list position is (hence first entry might be hidden on list opening).

Slolution 1:
If the list supports a "jump to first entry" (e.g. PgUp), then this is the easiest way (some wait()'s between type()'s might be needed)

Solution 2:
If only UP and DOWN is supported, we first have to key UP until the highlight has reached the topmost position and then we have to key UP until the list content does not change anymore.

the steps:
1. evaluate somehow the area of the topmost list entry (first)

2. key DOWN 2 times to make sure the topmost entry is not selected

3. loop until the first box entry is selected

while True:
    img = capture(first)
    type(Key.Up)
    if not first.nearby(2).exists(img,0): break

now we are on the topmost entry, but not necessarily at the top of the
list.

4. loop until positioned on the first entry of the list
we look wether the first entry has changed after a key UP, if not, we are at the top

while True:
    img = capture(first)
    type(Key.Up)
    if first.nearby(2).exists(img,0): break

the region first should have as little background as possible, to
concentrate on the area having pixels that change (high similarity,
should be above 0.9 or even better 0.95)

This can be evaluated rather easy:

r = selectRegion() # the target area
print r.nearby(10).find(capture(r))

together with the base position of the list, this helps to calculate the
needed offsets/positions/dimensions

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