How to recognized 2 identical controls on page?

Asked by priyank

Hello All,

I am new to Sikuli. I am using sikuli Jar with selenium web driver. I need to automate file upload control available on page. problem is that I have two file upload on same page.

EX:

1. Resume Upload : <File Upload Control>
2. Sample Upload : <File Upload Control>

                        s.click("E://Test Data//Resume.png", 0); // IMAGE FOR RESUME UPLOAD (JUST TAKEN IMAGE OF UPLOAD CONTROL)
   s.wait("E://Test Data//WaitPopup.png");
   s.click("E://Test Data//Textbox.png", 0);
   s.type(null, "E:/Test Data/Textbox.png", 0); // SELECT FILE TO UPLOAD
   s.click("E://Test Data//Open.png", 0);

I would like to automate RESUME file upload. when I run script using SIKULI IDE it is running fine but when I run script using Selenium TestNG, it is recognizing "Sample" file upload instead of "Resume" file upload.

PLEASE HELP ME OUT HOW SIKULI DIFFER SAME ELEMENTS ON PAGE.

LET ME KNOW IF ANY DETAILS NEEDED. APPRECIATED ALL YOUR HELP.

- PRIYANK

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
priyank
Solved:
Last query:
Last reply:

This question was reopened

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

either
--1. restrict the search region to the area, where you expect the button to be or
--2. use Pattern() to raise the needed similarity

--1.
usually one finds something fixed on the page, that should be found definitely in all cases and the define the search region relative to this match.
Match m = find(top_image);
Region r = m.below()
r.click(something_inside_r)

--2.
s.click( (new Pattern("E://Test Data//Resume.png")).similar(0.95), 0);
we ask to find only images with a similarity score of >= 0.95, which normally is sufficient to distinguish between similar buttons

Revision history for this message
priyank (priyank-shah) said :
#2

Hi RaiMan,

I really appreciated your quick and accurate response. I tried Option - 2 and it is working fine. Just eclipse IDE told me to do little correction. (Sharing because if any one refer this then it will be helpful.)

s.click((new Pattern("E://Test Data//Resume.png")).similar((float) 0.95), 0);

Solution given by you is working perfectly fine for me !!

Thanks a lot !!!!!

- PRIYANK

Revision history for this message
priyank (priyank-shah) said :
#3

Hi RaiMan,

I am so sorry, I tried couple of times and surprise to see the behavior.

Except, FIRST TIME, it is again identifying Resume file upload control as Sample file upload control . I tried with both options but could not resolve the problem.

Can you please help me out.

Regards,
Priyank

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

Thanks for the feedback.

Yes, that you have to to specify the similarity as a float is still a glitch in the Java API. I have it on my list.

BTW: 0.95F does the same and looks a bit nicer ;-)

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

Yes, I can help you out.

But I need screenshots and the images you use to search.

Zip everything together and upload it somewhere in the net (e.g. Dropbox/Public) and post the link here or send it to my mail at https://launchpad.net/~raimund-hocke (do not post my real mail address here pls.).

Revision history for this message
priyank (priyank-shah) said :
#6

Hello All,

My sincere apologies for multiple post. My problem gets resolved. There is nothing different solution which RaiMan said here but I just need to change code based on my application.

In My application, As said, we have two similar file upload control in sequence hence it was creating the problem.

1. Resume file upload
2. Sample file upload

So What I did is, I find match and create region of sample control (Which I don’t want to work with) and use above() method.

http://doc.sikuli.org/region.html

Above URL has really helped me out.

So code would look like,

                        Match m = s.find("..//Test Data//Sample.png"); //Sample file upload control.
   Region r = m.above();
   r.click("..//Test Data//ResumeBar.png"); //Input of Resume file upload

   s.wait("..//Test Data//WaitPopup.png");
   s.click("..//Test Data//Textbox.png", 0);
   s.type(null, "E:\\Test Data\\Textbox.png", 0);
   s.click("..//Test Data//OpenButon.png", 0);

Thanks a lot !!!!!

- PRIYANK

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

well done ;-)
thanks for coming back with your solution.

Revision history for this message
j (j-the-k) said :
#8

A third possibility is to use
findAll("..//Test Data//ResumeBar.png")
and sort the returned results by x- or y-coordinate.
Then you can pick the pattern you like, e.g. if you know the image is found twice and the right match is more left than the other, just pick the match with lower x-coordinate.
I know this might be more code to write but I just mention if for completeness :P
I guess it would also perform better because only one search is actually needed.

Revision history for this message
priyank (priyank-shah) said :
#9

Thanks for solution and sharing the information.