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:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java

License:Open Source License

private void captureScreenshot(WebDriver driver, String selector) throws IOException {
    File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    driver.get(dashboardUrl);/*w w w.j  av a 2s  .c  o  m*/
    System.out.println("Screenshot captured...");
    List<WebElement> elements = driver.findElements(By.cssSelector(selector));
    if (!elements.isEmpty()) {
        WebElement element = elements.get(0);
        BufferedImage fullImg = ImageIO.read(screenshot);
        Point point = element.getLocation();
        int eleWidth = element.getSize().getWidth();
        int eleHeight = element.getSize().getHeight();
        BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
        ImageIO.write(eleScreenshot, "png", screenshot);
        System.out.println("Cropping to get widget: " + selector.substring(1));
        FileUtils.copyFile(screenshot,
                new File(screenshotsDir + File.separator + selector.substring(1) + ".png"));
    }
}

From source file:org.specrunner.webdriver.actions.window.PluginPosition.java

License:Open Source License

@Override
protected void doEnd(IContext context, IResultSet result, WebDriver client, Options options, Window window)
        throws PluginException {
    Point p = null;
    try {/*from   w  w w .  j  ava  2  s .c  o  m*/
        p = window.getPosition();
    } catch (Exception e) {
        if (UtilLog.LOG.isDebugEnabled()) {
            UtilLog.LOG.debug(e.getMessage(), e);
        }
    }
    if (getX() == null && getY() == null) {
        throw new PluginException("PluginPosition action requires at least one of attributes 'x' and/or 'y'.");
    }
    if (p != null) {
        window.setPosition(new Point(getX() != null ? getX() : p.getX(), getY() != null ? getY() : p.getY()));
        result.addResult(Success.INSTANCE, context.peek());
    }
}

From source file:org.specrunner.webdriver.assertions.window.PluginPosition.java

License:Open Source License

@Override
protected void doEnd(IContext context, IResultSet result, WebDriver client, Options options, Window window)
        throws PluginException {
    Point p = null;
    try {/*from ww  w . j  a  v  a 2  s . c  o  m*/
        p = window.getPosition();
    } catch (Exception e) {
        if (UtilLog.LOG.isDebugEnabled()) {
            UtilLog.LOG.debug(e.getMessage(), e);
        }
    }
    if (getX() == null && getY() == null) {
        throw new PluginException(
                "PluginPosition assertion requires at least one of attributes 'x' and/or 'y'.");
    }
    if (getX() != null && p != null && !getX().equals(p.getX())) {
        throw new PluginException("X position does not match. Expected:" + getX() + ", received:"
                + (p != null ? p.getX() : "null"));
    }
    if (getY() != null && p != null && !getY().equals(p.getY())) {
        throw new PluginException("Y position does not match. Expected:" + getY() + ", received:"
                + (p != null ? p.getY() : "null"));
    }
    result.addResult(Success.INSTANCE, context.peek());
}

From source file:org.specrunner.webdriver.impl.PrepareDefault.java

License:Open Source License

@Override
public void prepare(AbstractPluginFind source, WebDriver client, WebElement... elements) {
    if (client instanceof JavascriptExecutor) {
        JavascriptExecutor executor = (JavascriptExecutor) client;
        if (elements != null) {
            for (WebElement e : elements) {
                if (e != null) {
                    try {
                        Point location = e.getLocation();
                        if (location != null) {
                            executor.executeScript("arguments[0].focus()", e);
                            executor.executeScript(
                                    "window.scrollTo(" + location.getX() + "," + location.getY() + ")");
                        }//w ww  .  ja va 2s.  com
                    } catch (WebDriverException ex) {
                        if (UtilLog.LOG.isTraceEnabled()) {
                            UtilLog.LOG.trace(ex.getMessage(), e);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.sugarcrm.voodoodriver.VDDMouse.java

License:Apache License

public void DnD(WebElement src, WebElement dst) {
    int src_x, src_y, dst_x, dst_y;
    Dimension srcDim = null;/*from   ww  w  .  java2s  .  c o m*/
    Dimension dstDim = null;
    String msg = "";
    this.reporter.Log("Starting DnD.");

    if (this.robo == null) {
        return;
    }

    Thread.currentThread();
    Point srcPoint = ((Locatable) src).getCoordinates().getLocationOnScreen();
    Point dstPoint = ((Locatable) src).getCoordinates().getLocationOnScreen();
    srcDim = src.getSize();
    dstDim = dst.getSize();
    src_x = srcPoint.getX() + (srcDim.getWidth() / 2);
    src_y = srcPoint.getY() + (srcDim.getHeight() / 2);
    dst_x = dstPoint.getX() + (dstDim.getWidth() / 2);
    dst_y = dstPoint.getY() + (dstDim.getHeight() / 2);

    msg = String.format("DnD Source Screen Coordinates: X => '%d' Y => '%d'", src_x, src_y);
    this.reporter.Log(msg);
    msg = String.format("DnD Dest Screen Coordinates: X => '%d' Y => '%d'", dst_x, dst_y);
    this.reporter.Log(msg);

    this.robo.mouseMove(srcPoint.x / 2, srcPoint.y / 2);
    this.robo.delay(800);
    this.robo.mousePress(InputEvent.BUTTON1_MASK);
    this.robo.delay(800);
    this.Move(src_x, src_y, dst_x, dst_y);
    this.robo.delay(800);
    this.robo.mouseRelease(InputEvent.BUTTON1_MASK);
    this.robo.delay(500);
    msg = "DnD Finished.";
    this.reporter.Log(msg);
}

From source file:org.suren.autotest.web.framework.log.TargetElementMark.java

License:Apache License

@Override
public void mark(WebElement ele, File file) throws IOException {
    BufferedImage bufImg = ImageIO.read(file);

    try {//from   w  w w  .ja  v a  2s. c o  m
        WebElement webEle = (WebElement) ele;
        Point loc = webEle.getLocation();
        Dimension size = webEle.getSize();

        Graphics2D g = bufImg.createGraphics();
        g.setColor(Color.red);
        g.drawRect(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
    } catch (StaleElementReferenceException se) {
    }
}

From source file:org.suren.autotest.web.framework.selenium.action.SeleniumHover.java

License:Apache License

@Override
public void hover(Element ele) {
    WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele);
    if (webEle == null) {
        logger.warn("can not found element.");
        return;//from  ww  w  .  j  a v a2 s .  com
    }

    if (!(ele instanceof FileUpload)) {
        Dimension size = webEle.getSize();
        Point loc = webEle.getLocation();
        int toolbarHeight = engine.getToolbarHeight();
        int x = size.getWidth() / 2 + loc.getX();
        int y = size.getHeight() / 2 + loc.getY() + toolbarHeight;

        try {
            new Robot().mouseMove(x, y);
        } catch (AWTException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteIOSDriver.java

License:Apache License

public static void dragFromToForDuration(WebDriverLikeCommandExecutor executor, Point from, Point to,
        int durationInSecs) {

    WebDriverLikeRequest request = executor.buildRequest(WebDriverLikeCommand.DRAG_FROM_TO_FOR_DURATION,
            ImmutableMap.of("fromX", Integer.toString(from.getX()), "fromY", Integer.toString(from.getY()),
                    "toX", Integer.toString(to.getX()), "toY", Integer.toString(to.getY()), "duration",
                    durationInSecs));/*w w  w .j  a va2  s. c  om*/
    executor.execute(request);
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteIOSDriver.java

License:Apache License

public static void pinchCloseFromToForDuration(WebDriverLikeCommandExecutor executor, Point from, Point to,
        int durationInSecs) {

    WebDriverLikeRequest request = executor.buildRequest(WebDriverLikeCommand.PINCH_CLOSE_FROM_TO_FOR_DURATION,
            ImmutableMap.of("fromX", Integer.toString(from.getX()), "fromY", Integer.toString(from.getY()),
                    "toX", Integer.toString(to.getX()), "toY", Integer.toString(to.getY()), "duration",
                    durationInSecs));/*w ww . j  ava2  s.c o  m*/
    executor.execute(request);
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteIOSDriver.java

License:Apache License

public static void pinchOpenFromToForDuration(WebDriverLikeCommandExecutor executor, Point from, Point to,
        int durationInSecs) {

    WebDriverLikeRequest request = executor.buildRequest(WebDriverLikeCommand.PINCH_OPEN_FROM_TO_FOR_DURATION,
            ImmutableMap.of("fromX", Integer.toString(from.getX()), "fromY", Integer.toString(from.getY()),
                    "toX", Integer.toString(to.getX()), "toY", Integer.toString(to.getY()), "duration",
                    durationInSecs));// w  w  w. jav a  2  s .  c o  m
    executor.execute(request);
}