← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #275461]: Get text from a notepad file and find it on screen

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
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()

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.