private BufferedImage takeScreenshotAsImage(WebDriver webdriver, WebElement element) { if (!(webdriver instanceof TakesScreenshot)) { log.warning("Cannot take screenshot because browser does not support screenshots"); return null; } byte[] screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.BYTES); Point elementLocation = element.getLocation(); try { BufferedImage img = ImageIO.read(new ByteArrayInputStream(screen)); int elementWidth = element.getSize().getWidth(); int elementHeight = element.getSize().getHeight(); if (elementWidth > img.getWidth()) { elementWidth = img.getWidth() - elementLocation.getX(); } if (elementHeight > img.getHeight()) { elementHeight = img.getHeight() - elementLocation.getY(); } return img.getSubimage(elementLocation.getX(), elementLocation.getY(), elementWidth, elementHeight); } catch (IOException e) { log.log(SEVERE, "Failed to take screenshot of " + element, e); return null; } catch (RasterFormatException e) { log.warning("Cannot take screenshot because element is not displayed on current screen position"); return null; } }
return null; int iframeHeight = iframe.getSize().getHeight(); SelenideTargetLocator switchTo = new SelenideTargetLocator(driver.config(), driver.getWebDriver()); switchTo.frame(iframe); int elementWidth = element.getSize().getWidth(); int elementHeight = element.getSize().getHeight(); if (elementWidth > iframeWidth) { elementWidth = iframeWidth - elementLocation.getX();
@Override public Rect findArea(WebPageElement webPageElement) { WebElement webElement = webPageElement.getWebElement(); Point location = webElement.getLocation(); Dimension size = webElement.getSize(); return new Rect(location.getX(), location.getY(), size.getWidth(), size.getHeight()); } }),
/** * Checks if the midpoint of an element is covered by any other element. * @return true if element is covered, false otherwise. */ public boolean isElementCovered(WebElement element) { int x = element.getLocation().x + element.getSize().width / 2; int y = element.getLocation().y + element.getSize().height / 2; WebElement topElem = (WebElement) executeScript("return document.elementFromPoint(" + x + "," + y + ");"); return !topElem.equals(element); }
/** * Gets width and height of the rendered element. See {@link org.openqa.selenium.WebElement#getSize()} * for more details. * * @return The size of the element on the page. */ @Override public Dimension getSize() { return wrappedElement.getSize(); }
@Override public Dimension getSize() { waitForVaadin(); return wrappedElement.getSize(); }
/** * Method to generate rectangle for the element since current version of * appium driver throws unimplemented exception * * @param element WebElement * @return Rectangle */ public Rectangle getRect(WebElement element) { return new Rectangle(element.getLocation(), element.getSize()); }
@Override public Integer execute(Context context, String... args) { return context.findElement(args[ARG_LOCATOR]).getSize().getHeight(); } }
@Override public Dimension doGetSize() { Dimension dim = element.getSize(); LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Size", dim.toString(), getName())); return dim; }
@Override public int getRight() { return getLeft() + getElement().getSize().getWidth(); }
public EditIssueTypeSchemePage moveFromAvailableToAboveSelected(final String availableIssueType, final String selectedIssueType) { WebElement source = getIssueTypeListItemFromAvailableOptions(availableIssueType); WebElement target = getIssueTypeListItemFromSelectedOptions(selectedIssueType); final double offset = target.getSize().getHeight() * DROP_TARGET_RATIO; dragAndDropWithOffset(source, target, (int) -offset); return this; }
public EditIssueTypeSchemePage moveFromSelectedToAboveAvailable(final String selectedIssueType, final String availableIssueType) { WebElement source = getIssueTypeListItemFromSelectedOptions(selectedIssueType); WebElement target = getIssueTypeListItemFromAvailableOptions(availableIssueType); final double offset = target.getSize().getHeight() * DROP_TARGET_RATIO; dragAndDropWithOffset(source, target, (int) -offset); return this; }
@Override public Coords ofElement(WebDriver driver, WebElement element) { Point point = element.getLocation(); Dimension dimension = element.getSize(); return new Coords( point.getX(), point.getY(), dimension.getWidth(), dimension.getHeight()); } }
private void dragAndDropWithOffset(final WebElement source, final WebElement target, final int offset) { Point currentLocation = source.getLocation(); Point destination = target.getLocation(); // We need to ensure we have the source in view. An egrgarious hack to make sure we can do this. // Assumes that scrolling to the top of the page will have our source AND target in the viewable area driver.findElement(By.tagName("body")).getSize(); int xOffset = destination.x - currentLocation.x + 1; int yOffset = destination.y - currentLocation.y + offset; Actions action = new Actions(driver).dragAndDropBy(source, xOffset, yOffset); action.perform(); }
@Override public void swipeRight(WebElement webElement) { logger.entering(webElement); Point currentLocation = webElement.getLocation(); Dimension elementSize = webElement.getSize(); int x = currentLocation.getX(); int y = currentLocation.getY(); int endx = x + elementSize.getWidth() - 1; this.swipe(x,y,endx, y, OPERATION_DURATION_MILLI_SECONDS); logger.exiting(); }
@Override public void swipeDown(WebElement webElement) { logger.entering(webElement); Point currentLocation = webElement.getLocation(); Dimension elementSize = webElement.getSize(); int x = currentLocation.getX(); int y = currentLocation.getY(); int endy = y + elementSize.getHeight() - 1; this.swipe(x, y, x, endy, OPERATION_DURATION_MILLI_SECONDS); logger.exiting(); }
@Override public void swipeRight(WebElement webElement) { logger.entering(webElement); Point point = webElement.getLocation(); Dimension dimension = webElement.getSize(); Point start = new Point(point.getX(), point.getY()); Point end = new Point(point.getX() + dimension.getWidth() - 1, point.getY()); performSwipeAction(start, end); logger.exiting(); }
@Override public void swipeUp(WebElement webElement) { logger.entering(webElement); Point point = webElement.getLocation(); Dimension dimension = webElement.getSize(); Point start = new Point(point.getX(), point.getY() + dimension.getHeight() - 1); Point end = new Point(point.getX(), point.getY()); performSwipeAction(start, end); logger.exiting(); }
public void shouldBeFullscreenAfterClickOnIcon() { HiViUap hiViUap = new HiViUap(driver, slotName); hiViUap.waitForAdLoaded(); hiViUap.waitForVideoStart(); hiViUap.clickFullscreenIcon(); Dimension windowSize = driver.findElement(By.cssSelector("body")).getSize(); Assertion.assertEquals(hiViUap.getVideoWidth(), windowSize.width); }