/** * @see TouchShortcuts#tap(int, int, int, int) * @param fingers Number of fingers used to perform a tap * @param x X coordinate to tap * @param y Y coordinate to tap * @param duration Duration of a tap */ public void tap(int fingers, int x, int y, int duration) { this.driver.tap(fingers, x, y, duration); }
/** * @see TouchShortcuts#tap(int, WebElement, int) * @param fingers Number of fingers used to perform a tap * @param element Element to tap * @param duration Duration of a tap */ public void tap(int fingers, WebElement element, int duration) { this.driver.tap(fingers, element, duration); }
@Override public void tap(int fingers, int x, int y, int duration) { ((AppiumDriver<?>) getWrappedDriver()).tap(fingers, x, y, duration); }
@Override public void tap(int fingers, WebElement element, int duration) { ((AppiumDriver<?>) getWrappedDriver()).tap(fingers, element, duration); }
/** * clickByImage is the main method that you should be using to tap on elements on screen using an image. * @param targetImgPath takes path to the screenshot of an element that you want to find. */ public void clickByImage(String targetImgPath) { Point2D coords = getCoords(takeScreenshot(), targetImgPath); if ((coords.getX() >= 0) && (coords.getY() >= 0)) { driver.tap(1, (int) coords.getX(), (int) coords.getY(), 100); } else { throw new ElementNotVisibleException("Element not found - " + targetImgPath); } }
public void clickByImage(String targetImgPath, double minSimilarityValue) { Point2D coords = getCoords(takeScreenshot(), targetImgPath, minSimilarityValue); if ((coords.getX() >= 0) && (coords.getY() >= 0)) { driver.tap(1, (int) coords.getX(), (int) coords.getY(), 100); } else { throw new ElementNotVisibleException("Element not found - " + targetImgPath); } } // Convenience method to long press an element on screen with 1 second press duration
AppiumDriver appiumDriver = new AppiumDriver(); String originalContext = appiumDriver.getContext(); Point coordinate = element.getLocation(); Dimension loc = element.getSize(); int centerX = loc.getWidth() / 2 + coordinate.getX(); int centerY = loc.getHeight() / 2 + coordinate.getY(); appiumDriver.context("NATIVE_APP"); appiumDriver.tap(1, centerX, centerY, 2); appiumDriver.context(originalContext);
public void tapAtCoordinates(int x, int y) throws Exception { if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate(x, y, 1); } else if (platform.equals(PlatformType.ANDROID)){ Dimension size = driver.manage().window().getSize(); if(y > size.getHeight() || x > size.getWidth()){ log("using adb tap at " + x + ", " + y); try{ //run eclipse from commandline to get path variable correct and find adb Process p = Runtime.getRuntime().exec("adb -s " + udid + " shell input tap " + x + " " + y); p.waitFor(); } catch (Exception e) { log(e.toString()); } } else { driver.tap(1, x, y, 1); } } else { driver.tap(1, x, y, 1); } }
public void tapAndHoldOnScreen(double x_offset, double y_offset, int duration) throws Exception { duration = duration * 1000; Dimension size = driver.manage().window().getSize(); Point middle = new Point(size.getWidth(), size.getHeight()); Point middleWithOffset = new Point(middle.x * x_offset, middle.y * y_offset); log("Coordinates with offset are: " + middleWithOffset.x + ", " + middleWithOffset.y); if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate((int) middleWithOffset.x, (int) middleWithOffset.y, duration); } else { driver.tap(1, (int) middleWithOffset.x, (int) middleWithOffset.y, duration); } }
public void tapAtRelativeCoordinates(double x_offset, double y_offset, int taps, double frequency) throws Exception { Dimension size = driver.manage().window().getSize(); Point middle = new Point(size.getWidth(), size.getHeight()); Point middleWithOffset = new Point(middle.x * x_offset, middle.y * y_offset); log("Tapping at coordinates: " + middleWithOffset.toString() + " when size of the screen is: " + size.toString()); for (int i = 0; i < taps; i++) { if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate((int) middleWithOffset.x, (int) middleWithOffset.y, 1); } else { driver.tap(1, (int) middleWithOffset.x, (int) middleWithOffset.y, 1); } sleep(frequency); } }
public boolean tapAndHoldImageOnScreen(String imageName, double x_offset, double y_offset, int duration, ImageRecognitionSettings settings, boolean with_assert) throws Exception { ImageSearchResult foundImage = findImageOnScreen(imageName, settings); if (with_assert){ assert(foundImage.isFound()); } if (foundImage.isFound() == false ) { return false; } Point top_left = foundImage.getImageLocation().getTopLeft(); Point top_right = foundImage.getImageLocation().getTopRight(); Point bottom_left = foundImage.getImageLocation().getBottomLeft(); double newX = top_left.x + (top_right.x - top_left.x) * x_offset; double newY = top_left.y + (bottom_left.y - top_left.y) * y_offset; log("Coordinates with offset are: " + newX + ", " + newY); if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate((int) newX, (int) newY, duration); } else { driver.tap(1, (int) newX, (int) newY, duration); } return true; }