How to compare text displayed on a GUI

Asked by Sikulipro

If i want to compare the text1 with text2 how to script it.

Question information

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

what is text1 and text2?

Revision history for this message
Sikulipro (saindane-harshal) said :
#2

text1 and text2 are normal label text or value in text field

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

either visually:
if <the-region-containing-text2>.exists(capture(<the-region-containing-text1>, 0):
    print "equal";
else:
    print "not equal"

or using the OCR-feature:
text1 = <the-region-containing-text1>.text()
text2 = <the-region-containing-text2>.text()
if text1 == text2:

about problems and usage of OCR look at the relevant questions and faqs.

Revision history for this message
Best obiwan-92 (obiwan-92) said :
#4

Thrid method :

If you can select your text (with a doubleClick), do :
type('c', KeyModifier.CTRL) # get the selected text in your clipboard
text1 = Env.getClipboard() # get it in run time
# Do the same thing for the text 2 and :
if text1 == text2 : print "they are identical"
else: print "they are not identical"

Revision history for this message
Sikulipro (saindane-harshal) said :
#5

Thanks obiwan-92, that solved my question.

Revision history for this message
Sikulipro (saindane-harshal) said :
#6

I still could not get the answer, i just need to compare the values in the text, it helped me to compare the control only but i need to compare value , how ?

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

all variants are in comments #3 and #4