Selenium Webdriver move mouse to Point

后端 未结 8 1067
小鲜肉
小鲜肉 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:44

    the solution is implementing anonymous class in this manner:

            import org.openqa.selenium.Point;
            import org.openqa.selenium.interactions.HasInputDevices;
            import org.openqa.selenium.interactions.Mouse;
            import org.openqa.selenium.interactions.internal.Coordinates;
    
            .....
    
            final Point image = page.findImage("C:\\Pictures\\marker.png") ;
    
            Mouse mouse = ((HasInputDevices) driver).getMouse();
    
            Coordinates imageCoordinates =  new Coordinates() {
    
                  public Point onScreen() {
                    throw new UnsupportedOperationException("Not supported yet.");
                  }
    
                  public Point inViewPort() {
                    Response response = execute(DriverCommand.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW,
            ImmutableMap.of("id", getId()));
    
        @SuppressWarnings("unchecked")
        Map mapped = (Map) response.getValue();
    
        return new Point(mapped.get("x").intValue(), mapped.get("y").intValue());
                  }
    
                  public Point onPage() {
                    return image;
                  }
    
                  public Object getAuxiliary() {
                    // extract the selenium imageElement id (imageElement.toString() and parse out the "{sdafbsdkjfh}" format id) and return it
                  }
                };
    
            mouse.mouseMove(imageCoordinates);
    

提交回复
热议问题