Example usage for org.openqa.selenium WebElement getLocation

List of usage examples for org.openqa.selenium WebElement getLocation

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getLocation.

Prototype

Point getLocation();

Source Link

Document

Where on the page is the top left-hand corner of the rendered element?

Usage

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Double tap./*  w  ww.ja  va2s. c  o  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.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Adds the common script./*from www . ja v  a2s  . c om*/
 * 
 * @param driver the driver
 * @param elementToTap the element to tap
 * @return the string
 */
private static String addCommonScript(final WebDriver driver, WebElement elementToTap) {

    return "window.jQuery(document.elementFromPoint(" + elementToTap.getLocation().getX() + ","
            + elementToTap.getLocation().getY() + "))";
}

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  w  w  .  j a v a2 s.c o 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.utils.WebElementUtils.java

License:Apache License

/**
 * Waits for the animation of specified WebElement to be finished within specified timeout.
 *
 * @param element WebElement to be checked.
 * @param timeout timeout in seconds within which the WebElement's animation has to be finished.
 *///from ww  w .  j ava 2s.  c om
public void waitForAnimationFinish(final WebElement element, int timeout) {
    final Deque<Point> locations = new ArrayDeque<>();
    isConditionMet(webDriver -> {
        Point currentLocation = element.getLocation();
        boolean animationStopped = false;
        if (!locations.isEmpty()) {
            animationStopped = locations.peekFirst().equals(currentLocation);
        }

        locations.addFirst(currentLocation);
        return animationStopped;
    }, timeout);
}

From source file:com.cognifide.qa.bb.webelement.WebElementConditions.java

License:Apache License

/**
 * Condition that checks if animation of provided WebElement finished.
 *
 * @param element WebElement to be checked
 * @return ExpectedCondition representing the above check
 *//*from  www  . ja v  a  2s.  c  om*/
public ExpectedCondition<WebElement> hasAnimationFinished(final WebElement element) {
    final Deque<Point> locations = new ArrayDeque<>();
    return webDriver -> {
        Point currentLocation = element.getLocation();
        boolean animationStopped = false;
        if (!locations.isEmpty()) {
            animationStopped = locations.peekFirst().equals(currentLocation);
        }

        locations.addFirst(currentLocation);
        return animationStopped ? element : null;
    };
}

From source file:com.coinbot.captcha.CaptchaDetector.java

License:Open Source License

private BufferedImage captureCaptcha(WebDriver driver, WebElement captcha) {
    WebElement iframe = null;//from   ww  w. j  av 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);
}

From source file:com.comcast.dawg.house.pages.IndexPage.java

License:Apache License

/**
 * Select the set-top checkbox./*from w  ww  .ja va  2 s .  c om*/
 *
 * @param  stbIds  ID of Set-top to be selected.
 */
public void selectStbCheckboxes(String... stbIds) {

    if (null == stbIds) {
        throw new IllegalArgumentException("STB id is null. No STB id is provided for selection.");
    }

    WebElement stbCheckbox = null;

    for (String stbId : stbIds) {

        stbCheckbox = getStbCheckboxElement(stbId);

        // For scrolling.
        ((JavascriptExecutor) driver).executeScript("window.scrollTo(0," + stbCheckbox.getLocation().y + ")");
        SeleniumWaiter.waitTill(STB_CHECKBOX_ELEMENT_WAIT);

        if (!stbCheckbox.isSelected()) {
            stbCheckbox.click();
            SeleniumWaiter.waitTill(STB_CHECKBOX_SELECTION_WAIT);
        }
    }
}

From source file:com.contactenergy.Tests.ContactBrowserTest.java

public void scrollandclick(String elementxpath) {
    WebElement submit = driver.get().findElement(By.xpath(elementxpath));

    Point coordinates = submit.getLocation();
    int s1 = coordinates.getX();
    int s2 = coordinates.getY();
    JavascriptExecutor exe1 = (JavascriptExecutor) driver.get();
    exe1.executeScript("window.scroll(" + s1 + ", " + s2 + ");");
    exe1.executeScript("arguments[0].click();", submit);
}

From source file:com.dhenton9000.selenium.generic.GenericAutomationRepository.java

/**
 * Determines visibility of an element in a window.
 * @param w/*  w w w  .  j ava 2 s . com*/
 * @return true if the element is in the window, false if not
 */
public boolean isElementScrolledIntoView(WebElement w) {

    if (w == null) {
        return false;
    }
    Point p = w.getLocation();
    Dimension d = getDriver().manage().window().getSize();
    java.awt.Rectangle r = new java.awt.Rectangle(d.getWidth(), d.getHeight());
    java.awt.Point awtPoint = new java.awt.Point(p.x, p.y);
    return r.contains(awtPoint);
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.HelpOverlayPageImpl.java

License:Open Source License

/**
 * Swipe direction.//from w  w w  . j a  v  a  2s  .  co  m
 * @param direction the direction
 * @see com.ecofactor.qa.automation.newapp.page.HelpOverlayPage#swipeDirection(java.lang.String)
 */
@Override
public void swipeDirection(final String direction) {

    final WebElement element = getSwipeContainer();
    if (direction.equalsIgnoreCase(RIGHT)) {
        getAction().doSwipeRight(element, element.getLocation().getX(), element.getLocation().getY(),
                element.getSize().getWidth() / 2, 0.1);
    } else {
        getAction().doSwipeLeft(element, element.getLocation().getX(), element.getLocation().getY(),
                element.getSize().getWidth() / 2, 0.1);
    }
}