List of usage examples for org.openqa.selenium.interactions Actions clickAndHold
public Actions clickAndHold()
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public void mouseDownAt(String locator, String coordString) { WebElement webElement = getWebElement(locator); scrollWebElementIntoView(webElement); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); if (Validator.isNotNull(coordString) && coordString.contains(",")) { String[] coords = coordString.split(","); int x = GetterUtil.getInteger(coords[0]); int y = GetterUtil.getInteger(coords[1]); actions.moveToElement(webElement, x, y); actions.clickAndHold(); } else {/*from ww w. jav a2 s . c o m*/ actions.moveToElement(webElement); actions.clickAndHold(webElement); } Action action = actions.build(); action.perform(); }
From source file:com.vaadin.testbench.elements.WindowElement.java
License:Apache License
/** * Moves the window by given offset.//from w ww. j av a 2s .c o m * * @param xOffset * x offset * @param yOffset * y offset */ public void move(int xOffset, int yOffset) { Actions action = new Actions(getDriver()); action.moveToElement(findElement(org.openqa.selenium.By.className("v-window-wrap")), 5, 5); action.clickAndHold(); action.moveByOffset(xOffset, yOffset); action.release(); action.build().perform(); }
From source file:com.vaadin.tests.components.calendar.CalendarResizeOverlappingEventsTest.java
License:Apache License
private void dragAndDrop(WebElement element, int yOffset) { /*//from w w w .j a va 2 s . c o m * Selenium doesn't properly drag and drop items in IE8. It tries to * start dragging an element from a position above the element itself. */ if (BrowserUtil.isIE8(getDesiredCapabilities())) { Actions action = new Actions(getDriver()); action.moveToElement(element); action.moveByOffset(0, 1); action.clickAndHold(); action.moveByOffset(0, yOffset); action.release(); action.build().perform(); } else { Actions action = new Actions(getDriver()); action.dragAndDropBy(element, 0, yOffset); action.build().perform(); } }
From source file:org.eclipse.che.selenium.pageobject.theia.TheiaTerminal.java
License:Open Source License
private void copyTerminalTextToClipboard(int terminalIndex) { Dimension textLayerSize = getTextLayer(terminalIndex).getSize(); final Actions action = seleniumWebDriverHelper.getAction(); final int xBeginCoordinateShift = -(textLayerSize.getWidth() / 2); final int yBeginCoordinateShift = -(textLayerSize.getHeight() / 2); seleniumWebDriverHelper.moveCursorTo(getTextLayer(terminalIndex)); // shift to top left corner seleniumWebDriverHelper.getAction().moveByOffset(xBeginCoordinateShift, yBeginCoordinateShift).perform(); // select all terminal area by mouse action.clickAndHold().perform(); seleniumWebDriverHelper.getAction().moveByOffset(textLayerSize.getWidth(), textLayerSize.getHeight()) .perform();//from w ww .j a va 2s.com action.release().perform(); // copy terminal output to clipboard String keysCombination = Keys.chord(CONTROL, INSERT); seleniumWebDriverHelper.sendKeys(keysCombination); // cancel terminal area selection clickOnTerminal(terminalIndex); }
From source file:org.evilco.bot.powersweeper.game.ScreenGameInterface.java
License:Apache License
/** * {@inheritDoc}// ww w . j a va2 s .c o m */ @Override public void moveToChunk(@NonNull ChunkLocation location) { getLogger().entry(); // check whether sane movement is possible if (this.chunkLocation != null) { // calculate distance ChunkLocation distance = this.chunkLocation.getDistance(location); ChunkLocation distanceSanitized = new ChunkLocation(distance); distanceSanitized.sanitize(); // verify whether sane movement is possible if (distanceSanitized.getX() <= SANE_MOVEMENT_THRESHOLD && distanceSanitized.getY() <= SANE_MOVEMENT_THRESHOLD) { // calculate distance long x = ((this.chunk.getWidth() * CELL_SIZE) * distance.getX()); long y = ((this.chunk.getHeight() * CELL_SIZE) * distance.getY()); // verify if (x > Integer.MAX_VALUE || y > Integer.MAX_VALUE) getLogger().warn("Sane movement threshold of " + SANE_MOVEMENT_THRESHOLD + " seems to be too big. Aborting."); else { // find HTML WebElement html = this.getPowersweeper().getDriverManager().getDriver() .findElement(By.tagName("html")); // build action Actions action = new Actions(this.getPowersweeper().getDriverManager().getDriver()); action.moveToElement(html, (CELL_SIZE / 2), (CELL_SIZE / 2)); action.clickAndHold(); action.moveByOffset(((int) x), ((int) y)); action.release(); // execute action.build().perform(); // wait for a few seconds try { Thread.sleep(2000); } catch (Exception ex) { getLogger().warn("Aliens wake us up to early."); } // update location this.chunkLocation = location; // force update this.update(); // trace getLogger().exit(); // skip return; } } } // open new URL this.getPowersweeper().getDriverManager().getDriver() .get(String.format(GAME_URL, location.getX(), location.getY())); // wait for a few seconds try { Thread.sleep(5000); } catch (Exception ex) { getLogger().warn("Aliens wake us up to early."); } // update location this.chunkLocation = location; // force update this.update(); // trace getLogger().exit(); }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
License:Open Source License
/** * Perform a left-drag from start point to end point relative to webelement (LeftUp corner). * @param we WebElement, the component relative to which to drag * @param start Point, the start point relative to the webelement * @param end Point, the end point relative to the webelement * @throws SeleniumPlusException//from w ww . ja v a2 s . c om */ public static void leftDrag(WebElement we, Point start, Point end) throws SeleniumPlusException { String debugmsg = StringUtils.debugmsg(false); try { IndependantLog.debug(debugmsg + " drag from " + start + " to " + end + " relative to webelement."); translatePoints(we, start, end); Robot.leftDrag(start, end); } catch (Exception e) { IndependantLog.warn(debugmsg + "Failed to drag by SAFS Robot: " + StringUtils.debugmsg(e)); IndependantLog.debug(debugmsg + "Try to drag by Selenium API."); try { Actions actions = new Actions(lastUsedWD); actions = actions.moveToElement(we, start.x, start.y); actions = actions.clickAndHold().moveByOffset((end.x - start.x), (end.y - start.y)).release(); actions.build().perform(); } catch (Exception e1) { IndependantLog.warn(debugmsg + "Failed to drag by Selenium API: " + StringUtils.debugmsg(e1)); throw new SeleniumPlusException("Failed to drag."); } } }