Selenium Webdriver move mouse to Point

后端 未结 8 1080
小鲜肉
小鲜肉 2020-12-05 11:24

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

8条回答
  •  生来不讨喜
    2020-12-05 11:46

    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.

提交回复
热议问题