Example usage for org.openqa.selenium Point getY

List of usage examples for org.openqa.selenium Point getY

Introduction

In this page you can find the example usage for org.openqa.selenium Point getY.

Prototype

public int getY() 

Source Link

Usage

From source file:io.selendroid.client.TouchActionBuilder.java

License:Apache License

/**
 * Non-standard (high-level) command to flick the screen in a given tick.
 * This method should not be used in MultiTouchActions, or if the pointer is already down in a
 * given position.//from  www. ja  v a  2 s .  co m
 * @param origin Point at which the flick should start
 * @param direction Direction in which to flick
 * @param distance Distance in which the flick should occur
 * @param duration Length of time the finger should be down on the screen
 * @return this
 */
public TouchActionBuilder flick(Point origin, FlickDirection direction, int distance, int duration) {
    Preconditions.checkState(!isDown);

    Map<String, Object> params = Maps.newHashMap();
    params.put("x", origin.getX());
    params.put("y", origin.getY());
    params.put("direction", direction.getDirection());
    params.put("distance", distance);
    params.put("duration", duration);

    addAction(TouchActionName.FLICK, params);
    return this;
}

From source file:net.codestory.simplelenium.filters.LazyShould.java

License:Apache License

private static boolean hasLocation(WebElement element, int x, int y) {
    Point location = element.getLocation();
    return location.getX() == x && location.getY() == y;
}

From source file:org.apache.archiva.web.test.parent.AbstractSeleniumTest.java

License:Apache License

public <V> V tryClick(By clickableLocator, Function<? super WebDriver, V> conditions, String message,
        int attempts, int maxWaitTimeInS) {

    getWebDriver().manage().window().maximize();
    int count = attempts;
    WebDriverWait wait = new WebDriverWait(getWebDriver(), maxWaitTimeInS);
    V result = null;/* w w  w  . j a va 2  s. co m*/
    Exception ex = null;
    WebElement el = null;
    while (count > 0) {
        try {
            el = wait.until(ExpectedConditions.elementToBeClickable(clickableLocator));
            Actions actions = new Actions(getWebDriver());
            actions.moveToElement(el).click().perform();
            result = wait.until(conditions);
            return result;
        } catch (Exception e) {
            logger.info("Error: {}, {}, {}", count, e.getClass().getName(), e.getMessage());
            if (el != null) {
                // Elements may be stale and throw an exception, if the location is requested
                try {
                    Point elLoc = el.getLocation();
                    logger.info("Location: x={} y={}", elLoc.getX(), elLoc.getY());
                } catch (Throwable e2) {
                    logger.info("Could not determine location");
                }
            }
            ex = e;
            count--;
        }
        try {
            Thread.currentThread().sleep(500);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
    if (ex != null) {
        Assert.fail(message);
    }
    return result;
}

From source file:org.cybercat.automation.components.Button.java

License:Apache License

public void clickOffset(Point cord) throws AutomationFrameworkException {
    LOG.info("Offset click to element: " + getElement().getTagName() + ", by coordinates: " + cord);
    try {//from   ww w  .j  a  v a 2s . co m
        Browser.getCurrentBrowser().getActions().moveToElement(getElement(), cord.getX(), cord.getY()).click()
                .perform();
    } catch (Exception e) {
        LOG.error("Exception on clickOffset execution for " + getName() + " element ." + " \n\t "
                + this.getClass().getSimpleName() + " class name, " + " \n\t " + this.getActualPath()
                + " xpath, ");
        throw new AutomationFrameworkException("Exception on clickOffset execution for " + getName()
                + " element ." + " \n\t " + this.getClass().getSimpleName() + " class name, " + " \n\t "
                + this.getActualPath() + " xpath, ", e);
    }
}

From source file:org.cybercat.automation.components.SvgChart.java

License:Apache License

public void dragAndDrop(Point from, Point to) throws AutomationFrameworkException {

    // since dragAndDrop in selenium works like piece of ... we should split drag and drop
    Browser.getCurrentBrowser().getActions().moveToElement(getElement(), from.getX(), from.getY())
            .clickAndHold().moveByOffset(to.getX(), to.getY()).perform();
    Browser.getCurrentBrowser().getActions().release().perform();
}

From source file:org.cybercat.automation.core.Browser.java

License:Apache License

/**
 * highlight active element with red color
 *///  ww  w .j a  v a2s. c  o m
public void highlightElement(WebElement element) {
    String bg = element.getCssValue("backgroundColor");
    try {
        this.executeScript("arguments[0].style.backgroundColor = '" + "red" + "'", element);
        Point point = element.getLocation();
        Dimension demention = new Dimension(point.x, point.y);// .getSize();
        eventManager.notify(new TakeScreenshotEvent(this, EffectType.RESIZ_BY_WIDTH,
                point.getX() + demention.getWidth(), point.getY() + demention.getHeight()));
    } catch (Exception e) {
        e.printStackTrace();
    }

    this.executeScript("arguments[0].style.backgroundColor = '" + bg + "'", element);
}

From source file:org.finra.jtaf.ewd.utils.ScreenshotUtils.java

License:Apache License

/***
 * You can use this method to take your control pictures. Note that the file should be a png.
 * /*  w  w w.j  ava 2s  .com*/
 * @param element
 * @param toSaveAs
 * @throws IOException 
 * @throws WidgetException 
 * @throws WidgetTimeoutException 
 * @throws Exception
 */
public static void takeScreenshotOfElement(IElement element, File toSaveAs)
        throws IOException, WidgetException {

    for (int i = 0; i < 10; i++) { //Loop up to 10x to ensure a clean screenshot was taken
        log.info("Taking screen shot of locator " + element.getLocator() + " ... attempt #" + (i + 1));

        //Scroll to element
        element.scrollTo();

        //Take picture of the page
        WebDriver wd = SessionManager.getInstance().getCurrentSession().getWrappedDriver();
        File screenshot;
        boolean isRemote = false;
        if (!(wd instanceof RemoteWebDriver)) {
            screenshot = ((TakesScreenshot) wd).getScreenshotAs(OutputType.FILE);
        } else {
            Augmenter augmenter = new Augmenter();
            screenshot = ((TakesScreenshot) augmenter.augment(wd)).getScreenshotAs(OutputType.FILE);
            isRemote = true;
        }
        BufferedImage fullImage = ImageIO.read(screenshot);
        WebElement ele = element.getWebElement();

        //Parse out the picture of the element
        Point point = ele.getLocation();
        int eleWidth = ele.getSize().getWidth();
        int eleHeight = ele.getSize().getHeight();
        int x;
        int y;
        if (isRemote) {
            x = ((Locatable) ele).getCoordinates().inViewPort().getX();
            y = ((Locatable) ele).getCoordinates().inViewPort().getY();
        } else {
            x = point.getX();
            y = point.getY();
        }
        log.debug("Screenshot coordinates x: " + x + ", y: " + y);
        BufferedImage eleScreenshot = fullImage.getSubimage(x, y, eleWidth, eleHeight);
        ImageIO.write(eleScreenshot, "png", screenshot);

        //Ensure clean snapshot (sometimes WebDriver takes bad pictures and they turn out all black)
        if (!isBlack(ImageIO.read(screenshot))) {
            FileUtils.copyFile(screenshot, toSaveAs);
            break;
        }
    }
}

From source file:org.finra.jtaf.ewd.widget.element.Element.java

License:Apache License

@Override
public int getLocationY() throws WidgetException {
    try {//from   w  w w . ja va2s. com
        Point p = findElement().getLocation();
        return p.getY();
    } catch (Exception e) {
        throw new WidgetException("Error while fetching Y location", locator, e);
    }
}

From source file:org.fitting.selenium.SeleniumDataTypeConverter.java

License:Apache License

/**
 * Convert a Selenium point to a Fitting {@link org.fitting.Point}.
 * @param point The Selenium point.// w w  w  .  java2 s.  c  o  m
 * @return The {@link org.fitting.Point}.
 */
public static Point convert(org.openqa.selenium.Point point) {
    return new Point(point.getX(), point.getY());
}

From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java

License:Open Source License

public int getVerticalPosition(String locator) {
    WebElement element = finder.find(locator);

    Point point = element.getLocation();

    LOG.createAppender().appendBold("Get Vertical Position:").appendCss(locator)
            .appendProperty("Y", point.getY()).log();

    return point.getY();
}