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:org.openlmis.UiUtils.TestWebDriver.java

License:Open Source License

public void scrollToElement(WebElement elementToClick) {
    // Scroll the browser to the element's Y position
    ((org.openqa.selenium.JavascriptExecutor) driver)
            .executeScript(String.format("window.scrollTo(0, %s);", elementToClick.getLocation().getY()));
}

From source file:org.paxml.selenium.webdriver.PickLocationTag.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w w . j  a v a  2s  .  co m*/
 */
@Override
protected Object onCommand(Context context) {
    return handleElements(new IElementHandler() {

        public Object handle(WebElement ele) {
            return ele.getLocation();
        }

    });
}

From source file:org.richfaces.bootstrap.demo.ftest.webdriver.pickList.fragment.PickListSelectionImpl.java

License:Open Source License

/**
 * Workaround for Drag and Drop/*ww w . j a v a 2 s  . c  o  m*/
 */
private void dragAndDropAction(WithOffset offset, Actions builder, WebElement source, WebElement target) {
    Point sourceLocation = source.getLocation();
    Point targetLocation = target.getLocation();
    int x = targetLocation.getX() - sourceLocation.getX() + offset.getOffset();
    int y = targetLocation.getY() - sourceLocation.getY() + offset.getOffset();
    builder.dragAndDropBy(source, x, y);
    //            builder.clickAndHold(source);
    //            builder.moveToElement(target);
    //            builder.moveByOffset(offset.getOffset(),offset.getOffset());//second move will throw exception
    //            builder.release();
}

From source file:org.richfaces.fragment.common.Utils.java

License:Open Source License

/**
 * Returns Locations of input element./*from   w ww  .j av  a 2s.c  o m*/
 *
 * @see Locations
 */
public static Locations getLocations(WebElement root) {
    Preconditions.checkNotNull(root, "The element cannot be null.");
    Point topLeft = root.getLocation();
    Dimension dimension = root.getSize();
    Point topRight = topLeft.moveBy(dimension.getWidth(), 0);
    Point bottomRight = topRight.moveBy(0, dimension.getHeight());
    Point bottomLeft = topLeft.moveBy(0, dimension.getHeight());
    return new Locations(topLeft, topRight, bottomLeft, bottomRight);
}

From source file:org.richfaces.photoalbum.ftest.webdriver.utils.PhotoalbumUtils.java

License:Open Source License

public static void scrollToElement(WebElement element) {
    Point location = element.getLocation();
    Utils.getExecutorFromElement(element).executeScript("scrollTo(" + location.x + "," + location.y + ")");
}

From source file:org.richfaces.showcase.contextMenu.AbstractContextMenuTest.java

License:Open Source License

protected void checkContextMenuRenderedAtCorrectPosition(WebElement target,
        RichFacesContextMenu ctxMenuFragment, Event showEvent,
        ExpectedCondition<Boolean> conditionTargetIsFocused, boolean selectingTargetTriggersAjax,
        boolean invokingMenuTriggersAjax) {

    if (conditionTargetIsFocused != null) {
        if (selectingTargetTriggersAjax) {
            guardAjax(target).click();//ww w .  j  av a2 s.co m
        } else {
            target.click();
        }
        Graphene.waitGui(webDriver).withTimeout(2, TimeUnit.SECONDS).until(conditionTargetIsFocused);
        waitFor(1000);// stabilization wait time, the waitGui before does not suffice
    }

    ctxMenuFragment.advanced().setShowEvent(showEvent);
    // using show() from fragment will make sure workaround is used for PhantomJS (RF-14034)
    // but it will still show the menu in upper left corner of the browser for PhantomJS
    if (invokingMenuTriggersAjax) {
        guardAjax(ctxMenuFragment.advanced()).show(target);
    } else {
        ctxMenuFragment.advanced().show(target);
    }
    Point locationOfTarget = target.getLocation();
    Point locationOfCtxMenu = ctxMenuFragment.advanced().getMenuPopup().getLocation();

    double witdth = getTargetWidth(target);
    double height = getTargetHeight(target);

    double halfOfDiagonal = Math.sqrt((height * height) + (witdth * witdth)) / 2.0;
    double distance = getDistance(locationOfTarget, locationOfCtxMenu);

    double result = halfOfDiagonal - distance;

    assertTrue("The context menu was not rendered on the correct position! The difference is: " + result,
            result >= 0 && result < TOLERANCE);
}

From source file:org.richfaces.tests.page.fragments.impl.Utils.java

License:Open Source License

/**
 * Returns Locations of input element./* w w w .  j a  v  a  2 s  . c o m*/
 * @see Locations
 */
public static Locations getLocations(WebElement root) {
    Point topLeft = root.getLocation();
    Dimension dimension = root.getSize();
    Point topRight = topLeft.moveBy(dimension.getWidth(), 0);
    Point bottomRight = topRight.moveBy(0, dimension.getHeight());
    Point bottomLeft = topLeft.moveBy(0, dimension.getHeight());
    return new Locations(topLeft, topRight, bottomLeft, bottomRight);
}

From source file:org.richfaces.tests.showcase.contextMenu.AbstractContextMenuTest.java

License:Open Source License

protected void checkContextMenuRenderedAtCorrectPosition(WebElement target, WebElement contextMenuPopup,
        InvocationType type, ExpectedCondition<Boolean> conditionTargetIsFocused) {
    Actions builder = new Actions(GrapheneContext.getProxy());

    if (conditionTargetIsFocused != null) {
        target.click();//  ww w .ja  v  a 2s.c  o  m
        Graphene.waitGui(webDriver).withTimeout(2, TimeUnit.SECONDS).until(conditionTargetIsFocused);
    }
    waitGui();

    // clicks in the middle of the target
    switch (type) {
    case LEFT_CLICK:
        builder.click(target);
        break;
    case RIGHT_CLICK:
        builder.contextClick(target);
        break;
    default:
        throw new IllegalArgumentException("Wrong type of context menu invocation!");
    }
    builder.build().perform();

    Graphene.waitGui().withTimeout(2, TimeUnit.SECONDS).until(element(contextMenuPopup).isVisible());

    Point locationOfTarget = target.getLocation();
    Point locationOfCtxMenu = contextMenuPopup.getLocation();

    double witdth = getTargetWidth(target);
    double height = getTargetHeight(target);

    double halfOfDiagonal = Math.sqrt((height * height) + (witdth * witdth)) / 2.0;
    double distance = getDistance(locationOfTarget, locationOfCtxMenu);

    double result = halfOfDiagonal - distance;

    assertTrue(result >= 0 && result < TOLERANCE,
            "The context menu was not rendered on the correct position! The difference is: " + result);
}

From source file:org.richfaces.tests.showcase.ftest.webdriver.page.AbstractTreePage.java

License:Open Source License

private void toggle(WebElement toToggle) {
    if (webDriver instanceof JavascriptExecutor) {
        Point location = toToggle.getLocation();
        JavascriptExecutor jsExecutor = (JavascriptExecutor) webDriver;
        jsExecutor.executeScript("window.moveTo(" + location.getX() + ", " + location.getY() + ")");
    }//from w  w  w  .  j a va  2  s  .  c  o  m
    toToggle.click();
    Graphene.waitAjax().withMessage("Unable to toggle the given element.")
            .until(Graphene.element(toToggle).isPresent());
}

From source file:org.safs.selenium.webdriver.lib.model.EmbeddedObject.java

License:Open Source License

/**
 * To check if an Element is visible on page.<br>
 * If the center of the element is in the container and is shown in the browser's client area, the<br>
 * element will be considered as visible on page.<br>
 * @param element Element, the element to check
 * @return boolean, true if the element is visible on page.
 * @throws SeleniumPlusException/*from  w ww  .  j  a v  a  2  s  .  c  o  m*/
 */
protected boolean isShowOnPage(Element element) throws SeleniumPlusException {
    WDLibrary.checkNotNull(element);

    try {
        WebElement item = element.getWebElement();
        org.openqa.selenium.Dimension itemD = item.getSize();
        org.openqa.selenium.Point itemCenterOffset = new org.openqa.selenium.Point(itemD.width / 2,
                itemD.height / 2);
        org.openqa.selenium.Point itemLoc = item.getLocation();
        org.openqa.selenium.Point itemCenterLoc = itemLoc.moveBy(itemCenterOffset.x, itemCenterOffset.y);

        WebElement container = webelement();
        org.openqa.selenium.Dimension containerD = container.getSize();
        org.openqa.selenium.Point containerLoc = container.getLocation();
        org.openqa.selenium.Point itemCenterLocRelativeToContainer = itemCenterLoc.moveBy(-containerLoc.x,
                -containerLoc.y);

        if (item.isDisplayed() //the item is considered displayed by Selenium
                && WDLibrary.isLocationInBounds(itemCenterLocRelativeToContainer, containerD) //the center of item is shown in the container
                && WDLibrary.isShowOnPage(item, itemCenterOffset) //the center of the item is shown in browser
        ) {
            return true;
        }
    } catch (Exception e) {
        IndependantLog.error(StringUtils.debugmsg(false) + "Met " + StringUtils.debugmsg(e));
    }

    return false;
}