List of usage examples for org.openqa.selenium WebElement getSize
Dimension getSize();
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Do tap./* ww w.j ava 2s.c o m*/ * * @param element the element * @param driver the driver */ public static void doTap(final WebElement element, final WebDriver driver) { Point point = element.getLocation(); double x = point.getX(); double y = point.getY(); Dimension dimesions = element.getSize(); int width = dimesions.width; int height = dimesions.height; final JavascriptExecutor js = (JavascriptExecutor) driver; final HashMap<String, Double> tapObject = new HashMap<String, Double>(); tapObject.put("tapCount", 1.0); tapObject.put("touchCount", 1.0); // tapObject.put("duration", 0.7); tapObject.put("x", x + width - 2); tapObject.put("y", y + height - 2); js.executeScript("mobile: tap", tapObject); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Do left tap.//from w w w.j a va 2s .co m * * @param element the element * @param driver the driver */ public static void doLeftTap(final WebElement element, final WebDriver driver) { LogUtil.log("Do Left Tap", LogLevel.HIGH); Point point = element.getLocation(); double x = point.getX(); double y = point.getY(); Dimension dimesions = element.getSize(); int height = dimesions.height; final JavascriptExecutor js = (JavascriptExecutor) driver; final HashMap<String, Double> tapObject = new HashMap<String, Double>(); tapObject.put("tapCount", 1.0); tapObject.put("touchCount", 1.0); x = x + 2; y = y + height + 2; tapObject.put("x", x); tapObject.put("y", y); LogUtil.log("X :" + x, LogLevel.HIGH); LogUtil.log("Y :" + y, LogLevel.HIGH); js.executeScript("mobile: tap", tapObject); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Do middle tap./* w ww. j a v a2s . c o m*/ * * @param element the element * @param driver the driver */ public static void doMiddleTap(final WebElement element, final WebDriver driver) { LogUtil.log("Do Middle Tap", LogLevel.HIGH); Point point = element.getLocation(); double x = point.getX(); double y = point.getY(); Dimension dimesions = element.getSize(); int width = dimesions.width; int height = dimesions.height; final JavascriptExecutor js = (JavascriptExecutor) driver; final HashMap<String, Double> tapObject = new HashMap<String, Double>(); tapObject.put("tapCount", 1.0); tapObject.put("touchCount", 1.0); tapObject.put("duration", 0.1); int midX = (int) x + (width / 2); int midY = (int) y + (height / 2); LogUtil.log("midX :" + midX, LogLevel.HIGH); LogUtil.log("midY :" + midY, LogLevel.HIGH); tapObject.put("duration", 0.7); tapObject.put("x", (double) midX); tapObject.put("y", (double) midY); js.executeScript("mobile: tap", tapObject); js.executeScript("mobile: tap", tapObject); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Do swipe page left.//from ww w . j a v a 2 s . c om * * @param element the element * @param driver the driver */ public static void doSwipePageLeft(final WebElement element, final WebDriver driver) { // final Point point = element.getLocation(); // double x = point.getX(); // double y = point.getY(); LogUtil.log("X :" + element.getLocation().getX(), LogLevel.HIGH); LogUtil.log("Y :" + element.getLocation().getY(), LogLevel.HIGH); final Dimension dimesions = element.getSize(); //int width = dimesions.width; //int height = dimesions.height; LogUtil.log("width :" + dimesions.width, LogLevel.HIGH); LogUtil.log("hieght:" + dimesions.height, LogLevel.HIGH); final JavascriptExecutor js = (JavascriptExecutor) driver; final HashMap<String, Double> tapObject = new HashMap<String, Double>(); tapObject.put("tapCount", 1.0); tapObject.put("touchCount", 1.0); tapObject.put("duration", 0.7); tapObject.put("startX", (double) getWindowWidth(driver)); tapObject.put("startY", (double) (getWindowHeight(driver) / 2)); tapObject.put("endX", 0.0); tapObject.put("endY", (double) (getWindowHeight(driver) / 2)); js.executeScript("mobile: swipe", tapObject); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Do swipe page right./*from www . j av a 2s . com*/ * * @param element the element * @param driver the driver */ public static void doSwipePageRight(final WebElement element, final WebDriver driver) { Point point = element.getLocation(); double x = point.getX(); double y = point.getY(); LogUtil.log("X :" + element.getLocation().getX(), LogLevel.HIGH); LogUtil.log("Y :" + element.getLocation().getY(), LogLevel.HIGH); Dimension dimesions = element.getSize(); int width = dimesions.width; // int height = dimesions.height; LogUtil.log("width :" + dimesions.width, LogLevel.HIGH); LogUtil.log("hieght:" + dimesions.height, LogLevel.HIGH); final JavascriptExecutor js = (JavascriptExecutor) driver; final HashMap<String, Double> tapObject = new HashMap<String, Double>(); tapObject.put("tapCount", 1.0); tapObject.put("touchCount", 1.0); tapObject.put("duration", 0.7); tapObject.put("startX", x + width); tapObject.put("startY", y); tapObject.put("endX", x); tapObject.put("endY", y); js.executeScript("mobile: swipe", tapObject); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Double tap./*from w w w . ja va2s . co m*/ * * @param driver the driver * @param element the element */ public static void doubleTap(final WebDriver driver, WebElement element) { Point point = element.getLocation(); int x = point.getX(); int y = point.getY(); Dimension dimesions = element.getSize(); int width = dimesions.width; int height = dimesions.height; ((TouchShortcuts) driver).tap(2, x + width - 2, y + height - 2, 1); /* * for (int i = 0; i < 2; i++) { * * Point point = element.getLocation(); double x = point.getX(); double * y = point.getY(); * * Dimension dimesions = element.getSize(); int width = dimesions.width; * int height = dimesions.height; * * final JavascriptExecutor js = (JavascriptExecutor) driver; final * HashMap<String, Double> tapObject = new HashMap<String, Double>(); * tapObject.put("tapCount", 2.0); tapObject.put("touchCount", 1.0); * tapObject.put("duration", 0.7); tapObject.put("fingers ", 2.0); * tapObject.put("x", x + width - 2); tapObject.put("y", y + height - * 2); js.executeScript("mobile: tap", tapObject); * WaitUtil.waitUntil(1); } */ }
From source file:com.cognifide.aet.job.common.collectors.screen.ScreenCollector.java
License:Apache License
private byte[] getImagePart(byte[] fullPage, WebElement webElement) throws IOException, ProcessingException { InputStream in = new ByteArrayInputStream(fullPage); try {//from w ww . j a v a2 s . co m BufferedImage fullImg = ImageIO.read(in); Point point = webElement.getLocation(); Dimension size = webElement.getSize(); BufferedImage screenshotSection = fullImg.getSubimage(point.getX(), point.getY(), size.getWidth(), size.getHeight()); return bufferedImageToByteArray(screenshotSection); } catch (IOException e) { throw new ProcessingException("Unable to create image from taken screenshot", e); } finally { IOUtils.closeQuietly(in); } }
From source file:com.cognifide.qa.bb.expectedconditions.CommonExpectedConditions.java
License:Apache License
/** * Check if provided element height is greater than expected height * * @param element - WebElement to check//from w ww . j av a 2 s .c o m * @param expectedHeight - expected height of an element * @return true if element height is greater than expected */ public static ExpectedCondition<Boolean> heightOfElementGreaterThan(final WebElement element, final int expectedHeight) { return driver -> element.getSize().getHeight() > expectedHeight; }
From source file:com.cognifide.qa.bb.webelement.WebElementConditions.java
License:Apache License
/** * Check if provided element height is greater than expected height * * @param element - WebElement to check * @param expectedHeight - expected height of an element * @return ExpectedCondition representing the above check *//*from w ww .j a v a 2 s . co m*/ public static ExpectedCondition<WebElement> heightOfElementGreaterThan(final WebElement element, final int expectedHeight) { return driver -> element.getSize().getHeight() > expectedHeight ? element : null; }
From source file:com.coinbot.captcha.CaptchaDetector.java
License:Open Source License
private BufferedImage captureCaptcha(WebDriver driver, WebElement captcha) { WebElement iframe = null;/* w w w . j a v a 2s . co m*/ try { iframe = captcha.findElement(By.tagName("iframe")); } catch (NoSuchElementException e) { } // Si tiene iframe es la version 2 if (iframe != null) { driver.switchTo().frame(iframe); JavascriptExecutor js2 = (JavascriptExecutor) driver; js2.executeScript("document.getElementById('loading').style.display = 'none'"); js2.executeScript("document.getElementById('overlay').style.display = 'inline'"); driver.switchTo().defaultContent(); } byte[] screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); BufferedImage imageScreen = null; try { imageScreen = ImageIO.read(new ByteArrayInputStream(screen)); } catch (IOException ex) { ex.printStackTrace(); } Point capLocation = captcha.getLocation(); Dimension capDimension = captcha.getSize(); return imageScreen.getSubimage(capLocation.x, capLocation.y, capDimension.width, capDimension.height); }