Selenium Webdriver move mouse to Point

0
0

I am currently trying to move the cursor to a point (org.openqa.selenium.Point) that has been set by checking for an occurrence of a marker on a live chart from which I can get no details but can find the X and Y coordinates of.

How can I move to the mouse to hover over said point to open the underlying JavaScript menu?

Current code

//finds marker on the current web page
Point image = page.findImage("C:\\Pictures\\marker.png") ;
//move mouse to this x,y location
driver
.getMouse().mouseMove((Coordinates) image);

This doesnt work as Point cannot be cast to org.openqa.selenium.interactions.internal.Coordinates.

  • You must to post comments
0
0

IMHO you should pay your attention to Robot.class

Still if you want to move the mouse pointer physically, you need to take different approach using Robot class

  Point coordinates = driver.findElement(By.id("ctl00_portalmaster_txtUserName")).getLocation();
Robot robot = new Robot();
robot
.mouseMove(coordinates.getX(),coordinates.getY()+120);

Webdriver provide document coordinates, where as Robot class is based on Screen coordinates, so I have added +120 to compensate the browser header.

Screen Coordinates: These are coordinates measured from the top left corner of the user’s computer screen. You’d rarely get coordinates (0,0) because that is usually outside the browser window. About the only time you’d want these coordinates is if you want to position a newly created browser window at the point where the user clicked.
In all browsers these are in event.screenX and event.screenY.

Window Coordinates: These are coordinates measured from the top left corner of the browser’s content area. If the window is scrolled, vertically or horizontally, this will be different from the top left corner of the document. This is rarely what you want.
In all browsers these are in event.clientX and event.clientY.

Document Coordinates: These are coordinates measured from the top left corner of the HTML Document. These are the coordinates that you most frequently want, since that is the coordinate system in which the document is defined.

More details you can get here

Hope this be helpful to you.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website