List of usage examples for org.openqa.selenium.interactions Mouse mouseMove
void mouseMove(Coordinates where, long xOffset, long yOffset);
From source file:com.preferanser.webtest.steps.EndUserSteps.java
License:Open Source License
@Step public EndUserSteps dragsCardToOtherLocation(Card card, TableLocation fromLocation, TableLocation toLocation) { TablePage page = getTablePage();//from w ww. j a v a 2s.c om Optional<WebElementFacade> maybeCard = page.getCardAtTableLocationElement(card, fromLocation); assertTrue(maybeCard.isPresent()); Optional<WebElementFacade> maybeTableLocation = page.getTableLocationElement(toLocation); assertTrue(maybeTableLocation.isPresent()); Mouse mouse = ((HasInputDevices) getDriver()).getMouse(); mouse.mouseMove(maybeCard.get().getCoordinates(), 3, 3); // grab the top left corner mouse.mouseDown(null); // at the current location mouse.mouseMove(maybeTableLocation.get().getCoordinates()); mouse.mouseUp(maybeTableLocation.get().getCoordinates()); return this; }
From source file:org.oneandone.qxwebdriver.ui.core.WidgetImpl.java
License:LGPL
public void dragOver(Widget target) throws InterruptedException { Mouse mouse = ((HasInputDevices) driver.getWebDriver()).getMouse(); Locatable root = (Locatable) driver.findElement(By.tagName("body")); //cast WebElement to Locatable Locatable sourceL = (Locatable) contentElement; Locatable targetL = (Locatable) target.getContentElement(); Coordinates coord = root.getCoordinates(); mouse.mouseDown(sourceL.getCoordinates()); //get source position (center,center) int sourceX = sourceL.getCoordinates().onPage().x + ((int) contentElement.getSize().width / 2); int sourceY = sourceL.getCoordinates().onPage().y + ((int) contentElement.getSize().height / 2); // get target position (center, center) int targetX = targetL.getCoordinates().onPage().x + ((int) target.getContentElement().getSize().width / 2); int targetY = targetL.getCoordinates().onPage().y + ((int) target.getContentElement().getSize().height / 2); //compute deltas between source and target position //delta must be positive, however //also we have to define the direction int deltaX;/*from ww w . j a va 2 s .c o m*/ int directionX = 1; //move direction is right int deltaY; int directionY = 1; //move direction is bottom deltaX = targetX - sourceX; if (deltaX < 0) { deltaX *= -1; directionX = -1; // move direction is left } deltaY = targetY - sourceY; if (deltaY < 0) { deltaY *= -1; directionY = -1; // move direction is top } //define base delta, which must be the higher one int baseDelta = deltaX; if (deltaY > deltaX) { baseDelta = deltaY; } // iterate base delta, set mouse cursor in relation to delta x & delta y int x = 0; int y = 0; for (int i = 1; i <= baseDelta; i += 4) { if (i > baseDelta) { i = baseDelta; } x = (int) sourceX + (deltaX * i / baseDelta * directionX); y = (int) sourceY + (deltaY * i / baseDelta * directionY); mouse.mouseMove(coord, x, y); //System.out.println(x +", "+ y); Thread.sleep(1); } // source has the same coordinates as target if (sourceX == targetX && sourceY == targetY) { mouse.mouseMove(targetL.getCoordinates(), x++, y); Thread.sleep(20); } }
From source file:org.specrunner.webdriver.actions.input.mouse.PluginMouseMoveCoordinates.java
License:Open Source License
@Override protected void doEnd(IContext context, IResultSet result, WebDriver client, HasInputDevices input, Mouse mouse) throws PluginException { if (getXoffset() != null && getYoffset() != null) { mouse.mouseMove(getCoordinates(), getXoffset(), getYoffset()); } else {//from w w w . ja v a2s. c o m mouse.mouseMove(getCoordinates()); } result.addResult(Success.INSTANCE, context.peek()); }