Login

Login
  • Register
  • VectorDesign blog

    Testing Automation and general Tech Geek stuff

    Java Robots and Selenium

    Posted in java on 19 March 2015 by vectordesign

    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

    Leave a Reply