Can any calculation be done using sikuli and coparision of two numeric values?

Asked by Subhasree Mohapatra

If I want to extract any value from a textbox and compare it with the any calculated value. Can this be done using sikuli?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

Sikuli is sitting on top of Jython (unless you're using the Java jars) which means that you can fully utilize the language. So if you want to compare numeric values just use Jython/Python syntax:

if var1 == var2:
    print "Yes"

Any one of those variables may be a result of another calculation.
Hope I understood your question correctly.

Cheers,
Eugene

Revision history for this message
Subhasree Mohapatra (mohapatra-subhasree13) said :
#2

Hi,
Thanks for your response. But can a scenario like , a numeric value from a textbox ( the value getting prepopulated on its own) picked by sikuli and matched with a value picked from an excel sheet and compared if they are same or not

Could you please help?

Revision history for this message
Eugene S (shragovich) said :
#3

To read excel file you can use Python xlrd module which should work fine with Sikuli.

You can download it here:
https://pypi.python.org/pypi/xlrd

I think you even don't have to install it, but just to unzip anywhere and update the path by:
sys.path.append(<xlrd directory>)

and, of course:

import xlrd

To read a value from textbox, you have two options:
1. Use the OCR feature
2. Copy the value to clipboard (Ctrl+C like way)

Please let me know if that solves your problem or you still need help.

Revision history for this message
Subhasree Mohapatra (mohapatra-subhasree13) said :
#4

Hi,

It solved the issue to some extent. but I am getting an error as
[error] AttributeError ( 'module' object has no attribute 'open_workbook' )

at the line which has been mentioned as

book=xlrd.open_workbook("C:\\Users\\Subhasree\\Desktop\\Values.xls")

Thanks in Advance!!

Revision history for this message
Eugene S (shragovich) said :
#5

Hi,

Please take a look at this question and answer. It looks like your issue:
https://answers.launchpad.net/sikuli/+question/222631

Revision history for this message
Subhasree Mohapatra (mohapatra-subhasree13) said :
#6

Hi,
 I went thru the question and answer but the error is still there. PFA my code
dir_xl ="C:\\Program Files\\SIKULI\\Lib\\xlrd"
import xlrd
r= find("1408880772792.png").below(100).find("1408811186449.png").left(100).click()
a=type("a" , Key.CTRL)
b=type("c", Key.CTRL)
p=Env.getClipboard()
print p
f=int(p)
print b
if f == 34:
    print ("Value is same")
else:
    print("not same")
book=xlrd.open_workbook("C:\\Users\\Subhasree\\Desktop\\Values.xls")

the error is still coming
[error] script [ Documents ] stopped with error in line 14
[error] AttributeError ( 'module' object has no attribute 'open_workbook' )

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

what version of xlrd?

do you have the correct folder in C:\\Program Files\\SIKULI\\Lib\\xlrd?
It must contain __init__.py (and the other .py) at the top level of the folder.

Revision history for this message
Subhasree Mohapatra (mohapatra-subhasree13) said :
#8

xlrd version 0.9.0
n the folder structure is
xlrd
--- _init_.py
--- other .py

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

I guess, the problem is, that xlrd 0.9.x does not work with Python language level 2.5 (it needs 2.6+).

Since you either had Sikuli RC3 or 1.0.1, you are using Jython 2.5.

You might try with xlrd 0.7.9 (use google).

Take care: the path you have stored the xlrd folder must be on sys.path (which is the case automatically, if it is in a folder Lib in the same fodder as the sikuli jar-file).

Revision history for this message
Subhasree Mohapatra (mohapatra-subhasree13) said :
#10

Thanks a lot!!! ...It worked...Thank u so much

Revision history for this message
Subhasree Mohapatra (mohapatra-subhasree13) said :
#11

Thanks RaiMan, that solved my question.