Looping through list of elements and finind expected text with OCR

Asked by Rares Pasca on 2018-12-13

Hello,

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

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-12-13
Last reply:
2018-12-13
RaiMan (raimund-hocke) said : #1

yes is possible.

Rares Pasca (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

yep

Rares Pasca (asheru93) said : #4

Thank you!

Rares Pasca (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):
        hover(myRegion)
        scrollIncrement = 0
        while scrollIncrement < 10:
            wheel(WHEEL_DOWN, scrollIncrement)
            myTextFromScreen = Region.text(MyRegion)
            if expectedStringElementElement in myTextFromScreen:
                click(elementToClick)
                break
            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 Rares Pasca for more information if necessary.

To post a message you must log in.