sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #13754
[Question #211517]: Combo box scrolling
New question #211517 on Sikuli:
https://answers.launchpad.net/sikuli/+question/211517
I have a widget called a combo box. If I click it, I get a scrollable list of options. I want to potentialy scroll through the entire list to find my desired option, since only some of the available options are visable at any one time and I don't know where I will start at in the list. An answer to Question #205813 suggest checking to see when the image stops changing as a means of determining having reached either end of the scroll list. But I can't get that onChange to work right.
A selected item in the scroll list is highlighted blue. Some image comparisons mistakenly key off of that blue bar, which no longer works when the blue bar does not change relative position. The selected item also shows up unhighlighted at the top of the list, which is another area I've tried to do image comparisons on.
I can't figure out how to manualy compare a saved image of the list from prior to the last scroll to what the list currently looks like. At times my comparisons are saying nothing has changed too soon, and at other times my comparisons are not detecting the fact that nothing has changed. If I do an exists, I have to do so within a region, instead of a previosly saved image, and I can't throw a similar qualifier on it. If I use getScore, I either can't attach that to the previous exists, or the score does not reflect my desired match.
My first combo box is just a list of months. I should be able to force some kind of nearly exact match on the text of the month name, but I can't.
import shutil
import os
Settings.ActionLogs=True
Settings.InfoLogs=True
Settings.DebugLogs=True
#setFindFailedResponse(PROMPT)
click(Pattern("Month-1.png").similar(0.66).targetOffset(11,0))
direction = WHEEL_DOWN # direction of wheeling/scrolling
reachedBottom = False # flag to see if bottom of the list was reached
reachedTop = False # flag to see if top of the list was reached
entryFound = False # is set True if the image was found
maxScrolls = 20 # maximum number of scroll attempts
# the image that is searched in the list
#goalImage = "October.png"
goalImage = "January.png"
click(Pattern("Latitude.png").targetOffset(-54,0))
wait(3)
click(Pattern("Month-1.png").similar(0.66).targetOffset(11,0))
#smallRegion = getLastMatch().below(150)
reg = getLastMatch()
#smallRegion = Region(reg.x + 40, reg.y, reg.w-40, reg.h+140)
smallRegion = Region(reg.x + 42, reg.y, reg.w-42, reg.h)
lastImage = capture(smallRegion)
shutil.copy(lastImage, os.path.join("c:\DKB\Sikuli", "image_a.png"))
for i in range(maxScrolls): # avoid endless loop
thisImage = capture(smallRegion)
shutil.copy(thisImage, os.path.join("c:\DKB\Sikuli", "image%02d.png"%(i)))
if (Region(smallRegion).exists(goalImage) == None): #no entry found #find fails & aborts
print("did not find %d"%(i))
if (direction == WHEEL_DOWN): # scroll down
type(Key.DOWN)
else:
type(Key.UP)
wait(4)
#Region(getLastMatch().nearby(200)).highlight(2)
#largeRegion = smallRegion.nearby(200).highlight(2)
#largeRegion = smallRegion.nearby()
#if (lastImage.exists(thisImage).similar(0.95)):
#if (Region(getLastMatch().nearby()).exists(lastImage)):
if (smallRegion.nearby(1).exists(lastImage)):
#if (smallRegion.nearby().exists(lastImage) and getLastMatch().getScore() > 0.8):
print("same as last time %f"%(getLastMatch().getScore()))
#getLastMatch().highlight(2)
#smallRegion.nearby().highlight(2)
if (direction == WHEEL_DOWN): # bottom reached, change wheel direction
reachedBottom = True
direction = WHEEL_UP
print("bottom")
else: # top reached, change wheel direction
reachedTop = True
direction = WHEEL_DOWN
print("top")
if (reachedTop == True and reachedBottom == True): # both ends of the dropdown-menu were reached, no more scrolling needed.
break
else:
print("not same as last time %f"%(getLastMatch().getScore()))
#getLastMatch().highlight(2)
#smallRegion.nearby().highlight(2)
lastImage = thisImage
else: # entry was found
entryFound = True
break
if (entryFound): # do stuff if successfull
click(goalImage)
print("found & clicked")
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.