← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #232718]: Can detect the text on screen but can't find it

 

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

Mark Weisler posted a new comment:
I tried essentially  your code and it worked properly for me.
I have a Web page open and it contains the string of interest in the region Sikuli will be searching. Then I run...

myReg= Region(100,100,500,600)  
myReg.highlight(2)
myText = myReg.text()
print myText

myReg.find("Hitz")  # succeeds as Hitz is found in the region
wait(3)
myReg.find("Hitzzzzzzzzzz") # fails as Hitzzzzzzzzzz is not found in the region
#this appears as a FindFailed error in the IDE

Please be sure the screen with the text has focus for Sikuli to see it.
You may be encountering a known OCR issue with Sikuli. (Apparently OCR
is not the most robust part of Sikuli at this time.)

Another version of this using exception handling is below and it works
properly also...

#script: OCRDemo33
# now using exception handling...

Settings.OcrTextSearch = True
Settings.OcrTextRead = True

myReg= Region(100,100,500,600)

myReg.highlight(2)
myText = myReg.text()
print myText

myReg.find("Hitz")  # succeeds as Hitz is found in the region
wait(1)

try:
        myReg.find("Hitzzzzzzzzzz")
        print "found string somehow" #should not execute this line as Hitzzzzz is not there.
        pass # it is there
except FindFailed:
        print("") #blank line
        print ("failed to find sought string")
        pass # just continue execution

wait(2)
try:
        myReg.find("Hitz")
        print("") #blank line
        print "found it again"
        pass # it is there
except FindFailed:
        print ("failed to find sought string")
        pass # continue

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.