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:com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.java

License:Open Source License

private boolean intersectsSelection(Point location, Dimension size) {
    // Test top left corner
    if (location.getX() < sLocation.getX() || location.getY() < sLocation.getY()) {
        return false;
    }/*www  .j av a 2  s  . c  o m*/
    // Test lower right corner
    if (location.getX() + size.getWidth() > sLocation.getX() + sSize.getWidth()
            || location.getY() + size.getHeight() > sLocation.getY() + sSize.getHeight()) {
        return false;
    }
    // Everything is inside the selection
    return true;
}

From source file:com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.java

License:Open Source License

private boolean isInSelection(Point location) {
    // Test top left corner
    if (location.getX() < sLocation.getX() || location.getY() < sLocation.getY()) {
        return false;
    }//w w w  . j  a v a 2 s .  c  om
    // Test lower right corner
    if (location.getX() - sLocation.getX() > sSize.getWidth()
            || location.getY() - sLocation.getY() > sSize.getHeight()) {
        return false;
    }
    // Everything is inside the selection
    return true;
}

From source file:com.vaadin.tests.components.tree.TreeScrollingOnRightClickTest.java

License:Apache License

@Test
public void testScrollingOnRightClick() throws Throwable {
    openTestURL();//from  w  w  w.ja  v  a  2 s.c o m

    // Focus tree
    WebElement tree = getDriver().findElement(By.id(TreeScrollingOnRightClick.TREE_ID));
    tree.click();

    // Move selection down 50 items
    for (int down = 0; down < 50; down++) {
        tree.sendKeys(Keys.ARROW_DOWN);
    }

    Thread.sleep(1000);

    // Get location of item 40
    Point item40Location = getTreeNode("Node 40").getLocation();

    // Right click on item 45
    WebElement item45 = getTreeNode("Node 45");
    new Actions(getDriver()).moveToElement(item45).contextClick(item45).perform();

    // Ensure location of item 40 is still the same (no scrolling)
    Point item40Location2 = getTreeNode("Node 40").getLocation();
    assertEquals(item40Location.getY(), item40Location2.getY());
}

From source file:com.vaadin.v7.tests.components.grid.GridSidebarPositionTest.java

License:Apache License

@Test
public void popupNotBelowBrowserWindow() {
    openTestURL();//from  w  w  w  .ja  v a 2  s  . c o  m
    GridElement gridAtBottom = $(GridElement.class).id(GridSidebarPosition.POPUP_WINDOW_MOVED_UP);
    getSidebarOpenButton(gridAtBottom).click();
    WebElement sidebarPopup = getSidebarPopup();
    Dimension popupSize = sidebarPopup.getSize();
    Point popupLocation = sidebarPopup.getLocation();
    int popupBottom = popupLocation.getY() + popupSize.getHeight();
    Dimension browserWindowSize = getDriver().manage().window().getSize();

    Assert.assertTrue(popupBottom <= browserWindowSize.getHeight());
}

From source file:com.vaadin.v7.tests.components.grid.GridSidebarPositionTest.java

License:Apache License

@Test
public void popupAbove() {
    openTestURL();//from   w ww .j a va  2 s.  c o  m
    GridElement gridPopupAbove = $(GridElement.class).id(GridSidebarPosition.POPUP_ABOVE);
    WebElement sidebarOpenButton = getSidebarOpenButton(gridPopupAbove);
    sidebarOpenButton.click();
    WebElement sidebarPopup = getSidebarPopup();
    Dimension popupSize = sidebarPopup.getSize();
    Point popupLocation = sidebarPopup.getLocation();
    int popupBottom = popupLocation.getY() + popupSize.getHeight();
    int sideBarButtonTop = sidebarOpenButton.getLocation().getY();
    Assert.assertTrue(popupBottom <= sideBarButtonTop);
}

From source file:com.vilt.minium.impl.debug.ElementsScreenshotInteraction.java

License:Apache License

@Override
protected void doPerform() {
    try {//from ww  w  .  jav  a2 s.c o m
        WebElement elem = getFirstElement();

        Point p = elem.getLocation();
        int width = elem.getSize().getWidth();
        int height = elem.getSize().getHeight();

        CoreWebElements<?> coreWebElements = getSource();
        WebElementsDriver<?> webDriver = coreWebElements.as(WebElementsDriverProvider.class).webDriver();
        byte[] screenshot = webDriver.getScreenshotAs(OutputType.BYTES);

        BufferedImage img = null;

        img = ImageIO.read(new ByteArrayInputStream(screenshot));
        BufferedImage dest = img.getSubimage(p.getX(), p.getY(), width, height);

        ImageIO.write(dest, "png", stream);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:dagaz.controllers.ChildController.java

private StaticImageScreenRegion videoFooterSection() {
    try {//from  w w  w.  ja  v a  2s.  c o  m
        WebElement element = driver.findElement(By.id("divFlashHolder"));
        Point point = element.getLocation();
        File ss = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        BufferedImage src = ImageIO.read(ss);
        BufferedImage screen = src.getSubimage(point.getX(), point.getY() + 300, element.getSize().getWidth(),
                element.getSize().getHeight() - 300);
        return new StaticImageScreenRegion(screen);
    } catch (IOException ex) {
        Logger.getLogger(ChildController.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:de.ppi.selenium.util.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.  java  2  s  .c  o  m*/
 *
 * @param element the webelement
 * @param toSaveAs the file where the screenshot should be save.
 * @param wd the webdriver.
 * @throws IOException if something goes wrong writing the result.
 */
public static void takeScreenshotOfElement(WebElement element, File toSaveAs, WebDriver wd) throws IOException {

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

        // Scroll to element
        // TODO Improvement element.scrollTo();

        // Take picture of the page
        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);

        // Parse out the picture of the element
        Point point = element.getLocation();
        int eleWidth = element.getSize().getWidth();
        int eleHeight = element.getSize().getHeight();
        int x;
        int y;
        if (isRemote) {
            x = ((Locatable) element).getCoordinates().inViewPort().getX();
            y = ((Locatable) element).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:entities.GPTPlanet.java

@Override
public void openAd() {
    openAdsPage();/*from   ww w  . j a v  a2  s .  c  o m*/
    ArrayList<String> links = getAllAds();
    for (String link : links) {
        int timeout = 30;
        appendLog("-- Opening Ad: " + link);
        driver.get(homeUrl + link);
        while (timeout > 0) {
            List<WebElement> elements = null;
            try {
                elements = driver.findElements(
                        By.xpath("//div[@id='surfbar' and not(contains(@style,'display: none'))]"));
            } catch (UnhandledAlertException ex) {
                appendLog("\tError: UnhandledAlertException");
                elements = driver.findElements(
                        By.xpath("//div[@id='surfbar' and not(contains(@style,'display: none'))]"));
            }
            if (elements.size() > 0) {
                WebElement e = elements.get(0);
                if (e.getText().contains("Wait please") || (e
                        .findElements(By.xpath(
                                "./div/div[@id='progressbar' and not(contains(@style,'display: none'))]"))
                        .size() > 0)) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    timeout--;
                } else if (e.getText().contains("Thanks for watching!")
                        || e.getText().contains("Invalid Advertisement")
                        || e.getText().contains("already visited")) {
                    break;
                } else if (e
                        .findElements(
                                By.xpath("./div[@id='focusoff' and not(contains(@style,'display: none'))]"))
                        .size() > 0) {
                    appendLog("--- Off Focus...... ---");
                    driver.switchTo().window(getCurrentWindow());
                    e.findElement(By.xpath("./a")).click();
                } else {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    timeout--;
                    if (timeout < (timeout / 3)) {
                        driver.navigate().refresh();
                    }
                }
            } else if (driver
                    .findElements(By.xpath("//div[@id='vnumbers' and not(contains(@style,'display: none'))]"))
                    .size() > 0) {
                try {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    WebElement element = driver
                            .findElement(By.xpath("//*[@id=\"vnumbers\"]/table/tbody/tr/td[2]"));
                    Point point = element.getLocation();
                    File ss = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                    BufferedImage src = ImageIO.read(ss);
                    BufferedImage screen = src.getSubimage(point.getX(), point.getY(),
                            element.getSize().getWidth(), element.getSize().getHeight());
                    StaticImageScreenRegion region = new StaticImageScreenRegion(screen);
                    boolean found = false;
                    for (File file : new File("./src/imgs").listFiles()) {
                        if (file.isFile()) {
                            for (ScreenRegion match : region.findAll(new ImageTarget(ImageIO.read(file)))) {
                                found = true;

                                System.out.println("---location: " + point + " - " + element.getSize());
                                System.out.println("---match: " + match.getCenter());
                                System.out.println("-order: " + ((match.getCenter().getX() / 50) + 1));
                                System.out
                                        .println("- target: " + (point.getX() + 50 + match.getCenter().getX()));
                                new Actions(driver).moveToElement(element, 0, 0)
                                        .moveByOffset(match.getCenter().getX(), match.getCenter().getY())
                                        .click().perform();
                                break;
                            }
                        }
                        if (found) {
                            break;
                        }
                    }
                    if (!found) {
                        ImageIO.write(screen, "PNG", new File("./src/imgs/detected/notfound-"
                                + link.substring(link.lastIndexOf("=") + 1) + ".png"));
                    }
                    //                        break;
                } catch (Exception ex) {
                    Logger.getLogger(ScarletClicks.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Neobux.class.getName()).log(Level.SEVERE, null, ex);
                }
                timeout--;
                if (timeout < (timeout / 3)) {
                    driver.navigate().refresh();
                }
            }
        }
    }
}

From source file:io.appium.java_client.AppiumDriver.java

License:Apache License

/**
 * Convenience method for "zooming in" on an element on the screen.
 * "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other.
 * NOTE:/*from   w w  w . j  a va  2  s . c  om*/
 * This convenience method slides touches away from the element, if this would happen to place one of them
 * off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api
 * instead of this method.
 *
 * @param el The element to pinch
 */
public void zoom(WebElement el) {
    MultiTouchAction multiTouch = new MultiTouchAction(this);

    Dimension dimensions = el.getSize();
    Point upperLeft = el.getLocation();
    Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,
            upperLeft.getY() + dimensions.getHeight() / 2);
    int yOffset = center.getY() - upperLeft.getY();

    TouchAction action0 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() - yOffset)
            .release();
    TouchAction action1 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() + yOffset)
            .release();

    multiTouch.add(action0).add(action1);

    multiTouch.perform();
}