2

I am automating a webpage using Selenium but there is one scenario where after clicking on a button, it opens up an Excel sheet. I need to enter a value in the cell of the Excel sheet. I am using Sikuli (in Eclipse) to do that but the header name of the cell is not unique. (Please refer the screenshot)

Reference screenshot. Trying to enter value in the cell highlighted in red box.

I am trying to enter the value in the cell highlighted in red box.

I tried the below code (in Eclipse) but it is clicking the wrong cell.

Screen s = new Screen();    
Pattern p = new Pattern("images/Cell.png");
s.find(p);
s.click(p);

Cell.png is as below:

Cell.png

2

After your code get executed it will click on some point in the Excel sheet. Then use keyboard key pressing to navigate to the correct cell. Then enter the values .

| improve this answer | |
  • Thanks for you reply. Some cells are write-protected navigating through the keyboard keys keeps giving error msg. – Alok Jan 10 '17 at 7:32
  • What about open the same file as a xlm or csv and then entering the appropriate data. – ChathuD Jan 10 '17 at 7:47
  • Actually I cannot control in which format the sheet opens. – Alok Jan 10 '17 at 7:57
1

You can use Python scripting to solve this and use the findall method of the Region object. This gives you a list of all matching images and then you can click/fill only the second occurrence.

| improve this answer | |
  • Thanks for your reply. your solution worked but I found another way used that in my code. i.e offsetting by using the following. I included the neighboring cell also in the cell.png and used s.find(N_Hash_Region).below(25).right(-200).left(5).click(); – Alok Jan 10 '17 at 7:42
0

For the reference I am giving the 3rd option That I tried and worked for me in addition to the 2 answers given by @timfredo & @chathuD.

I included the nearby cells to make the Cell.png unique. refer the screenshot below.

Previously Cell.png was as follows:

enter image description here

To make Cell.png unique I changed it to the below:

enter image description here

Now to click on the desired cell I used the following code.

Screen s = new Screen();    
Pattern p = new Pattern("images/Cell.png");

/*This will highlight the selected area for 3 seconds.*/
s.find(p).below(25).right(-200).left(5).highlight(3);

s.find(p).below(25).right(-200).left(5).click();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.