Get text from a notepad file and find it on screen

Asked by Ayush Sharma

HI,

I am new to sikuli and i want to find some text on screen (neither image nor extracted text from image). How do i do that?

I have created a notepad file in which i have written lines which it is supposed to read and find the same on screen.

Please help. Urgent.

Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

You are looking for a very problematic feature in SikuliX (find some text on the screen).
So before investing more, read:
https://answers.launchpad.net/sikuli/+question/275451

In any case start here:
http://sikulix.com

Then have a look at the docs and learn some basic Python.

Revision history for this message
Ayush Sharma (ayush-sharma31) said :
#2

Hi RaiMan

Thanks for answering.
In that case, i have another method to try. Please help me with it.

I want to store the images somewhere, then give the path to those images in a notepad file.
I want sikuli to read the notepad file, get the image info from there and then execute the given commands.

This is my code

C = open("‪CP.txt","w+")
lines = C.readlines()
for line in lines:
    click(line)

This CP.txt file contains the path to a particular image in each line with double quotes.

What am i doing wrong??

Revision history for this message
RaiMan (raimund-hocke) said :
#3

before again investing into too much boilerplate code, have a look at:
http://sikulix-2014.readthedocs.org/en/latest/scripting.html#image-search-path-where-sikulix-looks-for-image-files

If you put all images in one folder or more folders to group them somehow, then you file content can be reduced to only contain the relevant image filenames without path.

If each image filename is on one line, no apostrophes are needed at all.

the resulting code

# set the imagepath somehow according to the docs
C = open("‪CP.txt") # open for reading
lines = C.readlines()
for line in lines:
    click(line.strip())
C.close()

the strip() eliminates possible leading and trailing whitespace like e.g. the newline character

May be it is a good idea, to add a suitable wait() after the click, to give the GUI some time to process the click.

BTW: variables should be written starting with a lowercase letter and should have speaking names.
fileClicks = open("‪CP.txt") # open for reading
lines = fileClicks.readlines()
for line in lines:
    click(line.strip())
fileClicks.close()

Can you help with this problem?

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

To post a message you must log in.