How to read or get a string from text box or text area?

Asked by nate

Hi,

I am using Sikuli IDE 1.01 to automate testing for a Windows 7 desktop application. The program does not use the standard windows form control objects so Sikuli is proving to be a great tool to test this application.

Right now, I need to be able to verify if the text contained in a text field is of a certain value or not.

Is there a way I can read text values from a text box or a text field?

thanks

Nate

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
Eugene S (shragovich) said :
#1

Hi,

Sikuli does not use element handlers so you can't just read values from a text box. You can follow one of the below approaches:

1. Use OCR to read the text in a predefined area (be aware of OCR limitations)
2. If the text is clickable and "selectable", you can just select it and copy it directly to your buffer.

Eugene

Revision history for this message
Nurbergen (87073525266-w) said :
#2

did you find answer of it?

Revision history for this message
IgorG (qa-ukraine) said :
#3

A possible solution may looks like:
    matches = r.listText() # get the match regions occupied by the pixels of a word
    for m in matches:
        #m.highlight(1)
        word = m.getText()
        labelX = m.getX()
        labelY = m.getY()
        labelH = m.getH()
        labelW = m.getW()

To compare the strings Python has a handy function SequenceMatcher in the library called difflib :
import difflib
def howSimilar(str1, str2):
    return difflib.SequenceMatcher(None, str1, str2).ratio()

It suppose to return a number from 0 to 1.

Can you help with this problem?

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

To post a message you must log in.