Looping through list of elements and finind expected text with OCR

Asked by Asheru on 2018-12-13


I have a list of elements and i need to select a certain element. For that I have to scroll the list. It is possible to create a method that scrolls through this list and when it finds my expected elements clicks it? I was thinking to use the OCR to recognize the text from the element that I'm expecting to find ?

Thank you

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

yes is possible.

Asheru (asheru93) said : #2

Ok thanks.

So the approach would be something like this:

define a region in screen
define the element that i want to find, a string basically
inside a for loop iterate with OCR until my element is found while scrolling

RaiMan (raimund-hocke) said : #3


Asheru (asheru93) said : #4

Thank you!

Asheru (asheru93) said : #5

This is my solution for this, i hope it will work on you aswell.

Here are the elements passed to the method:
myRegion = your region where you want to scroll
expectedStringElement = the text that is found on the element you want to click for example "Create Account"
elementToClick = define an image containing the element that you want to click for example "Create Account" button image

    def findElementFromList(myRegion,expectedStringElement,elementToClick):
        scrollIncrement = 0
        while scrollIncrement < 10:
            wheel(WHEEL_DOWN, scrollIncrement)
            myTextFromScreen = Region.text(MyRegion)
            if expectedStringElementElement in myTextFromScreen:
            scrollIncrement += 1

Struggled a bit to make it work, maybe because of my app that I'm testing but in the end very helpful and reusable evrey time is needed.

Can you help with this problem?

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

To post a message you must log in.