2

I am working on automation project to automate web application testing using Selenium webdriver with Java. However, we have got stuck for moving mouse pointer to required location (x,y) on page. We have used Actions class to achieve this, but this class does not move the mouse pointer on location it is just moving focus of the mouse and we need to mouse over element to open tool tip. We have tried using other framework SIKULI, which work on images, which work fine but it does not go to each and every element/image on page, it select the random image which match it.

However, we have graph on web page which has multiple point which has tool tip which open only when mouse is physical hover on element. Now, we have come across the new thought, that is get the location (x,y) of element on page and using Robot class to move the mouse on required location, but when we pass the (x,y) position of element on page, it move the mouse on some other position on screen, the reason is robot class will take the screen resolution and move the mouse based on (x,y) position.

Can we pragmatically find the exact position based on desktop screen size, for example Web Page size is (3081,5172) and based on webpage element location is (723,415), now what will the position of element on screen when screen size is (1920,1080)?

Till Now below is the code I am using it.

 Robot robot=new Robot();
 Actions action = new Actions(driver);
 action.moveToElement(ele).click().build().perform();
 robot.mouseMove(ele.getLocation().getX(), ele.getLocation().getY());

Note: action.moveToElement method does not move the mouse pointer physical on required element and robot.mouseMove method move the mouse with desktop screen which gives incorrect out put.

Your inputs will be highly appreciate

Dani
  • 21
  • 2
  • Have you tried anything so far? If so, please edit your question and include some snippets. It would help people answering your question greatly! Read more about [how to ask a great question](http://stackoverflow.com/help/how-to-ask). – methode Jul 05 '15 at 09:32
  • Cant Selenium give you onscreen position of html element ? – Antoniossss Jul 05 '15 at 09:46
  • @Antoniossss, we get the position of html element from selenium, but when we pass value to robot class it calculate the x,y position based on desktop screen size and not based on page size... – Dani Jul 05 '15 at 10:41
  • You mean that positions is relative to the browser not to the screen?\ – Antoniossss Jul 05 '15 at 10:49
  • This is related to http://stackoverflow.com/questions/14655581/selenium-webdriver-and-html-window-location-by-using-java – Antoniossss Jul 05 '15 at 10:51

1 Answers1

0

"Your statement: We have tried using other framework SIKULI, which work on images, which work fine but it does not go to each and every element/image on page, it select the random image which match it."

If the image provided to sikuli to finding purpose has multiple matches at given simillarity (0.7 is default ) then to which match Sikuli can click is unpredicted. For such case you can refine your search by giving higher matching percentage:

pattern target = new Pattern ("img path/path").similar( (float) 0.85);

Other approach is to used findAll(..) command which returns the match iterator for all the match. then you can sort them vertically or horizontally (this is very tricky and needs some more coding) and use them.

Another approach in sikuli use this :

Screen s = new Screen();
s.hover(new Location (int x-coordinate, int y-coordinate));
Umesh
  • 121
  • 6