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?
//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
.
Selenium will right click on your element, which will result in the context menu being displayed at the bottom right corner of your cursor. Once you see the position of the context menu, you will know whether Selenium is clicking on the right element.
We can perform drag and drop action in Selenium with the help of Actions class. In order to perform the drag and drop movement we will use dragAndDrop (source, target) method. Finally use build(). perform() to execute all the steps.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With