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.vaadin.tests.components.calendar.CalendarRescheduleEventTest.java

License:Apache License

private int rescheduleEvent(int yOffset) {
    WebElement eventCaption = getDriver().findElement(By.className("v-calendar-event-caption"));

    dragAndDrop(eventCaption, 0, yOffset);

    eventCaption = getDriver().findElement(By.className("v-calendar-event-caption"));
    return eventCaption.getLocation().getY();
}

From source file:com.vaadin.tests.components.calendar.CalendarResizeOverlappingEventsTest.java

License:Apache License

private void initParams() {
    WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot"));
    int dateSlotWidth = dateSlot.getSize().getWidth();
    noOverlapWidth = dateSlotWidth;//from w w w .  j av  a  2 s.  co m
    oneOverlapWidth = dateSlotWidth / 2;
    twoOverlapsWidth = dateSlotWidth / 3;

    Comparator<WebElement> startTimeComparator = new Comparator<WebElement>() {
        @Override
        public int compare(WebElement e1, WebElement e2) {
            int e1Top = e1.getLocation().getY();
            int e2Top = e2.getLocation().getY();
            return e1Top - e2Top;
        }
    };

    List<WebElement> eventElements = getDriver().findElements(By.className("v-calendar-event-content"));
    Collections.sort(eventElements, startTimeComparator);
    firstEvent = eventElements.get(0);
    secondEvent = eventElements.get(1);
    thirdEvent = eventElements.get(2);

    List<WebElement> resizeBottomElements = getDriver()
            .findElements(By.className("v-calendar-event-resizebottom"));
    Collections.sort(resizeBottomElements, startTimeComparator);
    firstEventBottomResize = resizeBottomElements.get(0);
    secondEventBottomResize = resizeBottomElements.get(1);
    thirdEventBottomResize = resizeBottomElements.get(2);
}

From source file:com.vaadin.tests.components.datefield.DefaultDateFieldPopupPositionTest.java

License:Apache License

@Override
protected void checkPopupPosition() {
    DateFieldElement field = $(DateFieldElement.class).first();
    int right = field.getLocation().getX() + field.getSize().getWidth();
    WebElement popup = getPopup();

    Assert.assertTrue("Calendar popup has wrong X coordinate=" + popup.getLocation().getX()
            + " , right side of the field is " + right, popup.getLocation().getX() >= right);
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridColumnReorderTest.java

License:Apache License

@Test
public void testColumnReordering_bigWidth_dragElementPositionCorrect() {
    openTestURL();/*from   www . j ava 2 s.  co m*/
    toggleColumnReordering();
    selectMenuPath("Component", "Size", "Width", "900px");
    assertColumnHeaderOrder(0, 1, 2, 3);

    GridCellElement draggedHeaderCell = getGridElement().getHeaderCell(0, 1);
    final int xOffset = 500;
    new Actions(getDriver()).moveToElement(draggedHeaderCell, 20, 10).clickAndHold().moveByOffset(xOffset, 0)
            .build().perform();

    WebElement floatingDragElement = findElement(By.className("dragged-column-header"));

    int expectedLeft = draggedHeaderCell.getLocation().getX() + xOffset + 20
            - (floatingDragElement.getSize().getWidth() / 2);
    int realLeft = floatingDragElement.getLocation().getX();

    assertTrue("Dragged element location wrong, expected " + expectedLeft + " was " + realLeft,
            Math.abs(expectedLeft - realLeft) < 10);
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridColumnReorderTest.java

License:Apache License

@Test
public void testDropMarker_sidebarOpenButtonVisible_dropMarkerOnCorrectPosition() {
    // using runo since there the sidebar opening button is wider than the
    // scroll deco, and because using Valo has some TB issues
    openTestURL("theme=runo");

    selectMenuPath("Component", "Size", "Width", "100%");
    selectMenuPath("Component", "Columns", "All columns hidable");
    toggleColumnReordering();//from   w  ww  .  jav  a  2s.c om
    scrollGridHorizontallyTo(100000);

    new Actions(getDriver()).clickAndHold(getDefaultColumnHeader(10)).moveByOffset(800, 0).build().perform();

    WebElement dragDropMarker = findElement(By.className("v-grid-drop-marker"));
    WebElement sidebar = findElement(By.className("v-grid-sidebar"));

    int dragDropMarkerX = dragDropMarker.getLocation().getX();
    int sidebarX = sidebar.getLocation().getX();
    assertTrue("Drop marker misplaced " + dragDropMarkerX + " compared to sidebar open button " + sidebarX,
            dragDropMarkerX <= sidebarX);
}

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

License:Apache License

@Test
public void testDetailsOnSort() {
    openTestURL();//w  w w . j  av  a  2 s. c om
    GridElement grid = $(GridElement.class).first();

    // Open a details rows
    grid.getCell(0, 0).click();

    GridCellElement cell = grid.getHeaderCell(0, 0);
    cell.click();
    cell.click();

    cell = grid.getCell(2, 0);
    WebElement spacer = findElement(By.className("v-grid-spacer"));
    Assert.assertEquals("Grid was not sorted correctly", "Hello 0", cell.getText());
    Assert.assertEquals("Details row was not in correct location",
            cell.getLocation().getY() + cell.getSize().getHeight(), spacer.getLocation().getY());

}

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

License:Apache License

@Test
public void popupNotBelowBrowserWindow() {
    openTestURL();/*  www . ja  v a  2s  .  co  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.  ja  va  2s  . 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 w  ww. j  a  va  2 s  . com
        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 {//w  w  w.  j a va 2 s .  co 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;
    }
}