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.smash.revolance.ui.materials.mock.webdriver.browser.MockedBrowserController.java

License:Open Source License

@Override
public synchronized void notify(JSonWireEvent event) {
    String name = (String) event.getProp("command.name");
    String path = (String) event.getProp("command.path");
    String elementId = (String) event.getProp("command.elementId");
    String htmlAttribute = (String) event.getProp("command.elementHtmlAttribute");
    String cssAttribute = (String) event.getProp("command.elementCssAttribute");

    System.out.println("Receiving command: " + name + " with path: " + path);

    Map<String, Object> commandPayload = (Map<String, Object>) event.getProp("command.payload");

    // Just the value part in the payload
    Map<String, Object> resultPayload = new HashMap<String, Object>();

    if (isCommand(event, DriverCommand.NEW_SESSION)) {
        browser = new MockedBrowser();

        resultPayload.put("browserName", this.getClass().getSimpleName());
        resultPayload.put("browserPlatform", OS.isFamilyUnix() ? "LINUX" : "WINDOWS");
        resultPayload.put("browserVersion", "0.0.1-SNAPSHOT");
    }/*from w  w w .j  a  va 2  s  .c  o m*/
    if (isCommand(event, DriverCommand.SET_WINDOW_SIZE)) {
        browser.setSize((Integer) commandPayload.get("width"), (Integer) commandPayload.get("height"));
    }
    if (isCommand(event, DriverCommand.GET_WINDOW_SIZE)) {
        Dimension dim = browser.getDimension();
        resultPayload.put("width", dim.getWidth());
        resultPayload.put("height", dim.getHeight());
    }
    if (isCommand(event, DriverCommand.SET_WINDOW_POSITION)) {
        browser.setLocation((Integer) commandPayload.get("x"), (Integer) commandPayload.get("y"));
    }
    if (isCommand(event, DriverCommand.GET_WINDOW_POSITION)) {
        Point location = browser.getLocation();
        resultPayload.put("x", location.getX());
        resultPayload.put("y", location.getY());
    }
    if (isCommand(event, DriverCommand.GET_CURRENT_URL)) {
        resultPayload.put("url", browser.getUrl());
    }
    if (isCommand(event, DriverCommand.GET)) {
        try {
            browser.goToUrl((String) commandPayload.get("url"));
        } catch (Exception e) {
            System.err.println(e);
        }
    }
    if (isCommand(event, DriverCommand.EXECUTE_SCRIPT)) {
        resultPayload.put("value", browser.executeJavaScript((String) commandPayload.get("script"),
                (Object[]) commandPayload.get("args")));
    }
    if (isCommand(event, DriverCommand.GET_ALERT_TEXT)) {
        resultPayload.put("alertStatusCode", ErrorCodes.NO_ALERT_PRESENT);
        resultPayload.put("alertMessage", "No alert is present");
    }
    if (isCommand(event, DriverCommand.GET_TITLE)) {
        resultPayload.put("title", browser.getTitle());
    }
    if (isCommand(event, DriverCommand.SCREENSHOT)) {
        resultPayload.put("screenshot", browser.takeScreenshot());
    }
    if (isCommand(event, DriverCommand.FIND_ELEMENTS)) {
        List<String> elements = browser.findElements((String) commandPayload.get("value"));
        resultPayload.put("elementList", buildElementList(elements));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_LOCATION)) {
        Point location = browser.getElementLocation(elementId);

        resultPayload.put("elementX", String.valueOf(location.getX()));
        resultPayload.put("elementY", String.valueOf(location.getY()));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_SIZE)) {
        Dimension dim = browser.getElementSize(elementId);

        resultPayload.put("elementW", String.valueOf(dim.getWidth()));
        resultPayload.put("elementH", String.valueOf(dim.getHeight()));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_TAG_NAME)) {
        resultPayload.put("elementTagName", browser.getElementTag(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_TEXT)) {
        resultPayload.put("elementText", browser.getElementText(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_ATTRIBUTE)) {
        resultPayload.put("elementHtmlAttributeValue",
                browser.getElementHtmlAttribute(elementId, htmlAttribute));
    }
    if (isCommand(event, DriverCommand.IS_ELEMENT_DISPLAYED)) {
        resultPayload.put("isElementDisplayed", browser.isElementDisplayed(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_VALUE_OF_CSS_PROPERTY)) {
        resultPayload.put("elementCssAttributeValue", browser.getElementCssAttribute(elementId, cssAttribute));
    }
    event.setProp("command.value", resultPayload);
    notifyAll();
}

From source file:com.smash.revolance.ui.materials.mock.webdriver.PageTest.java

License:Open Source License

@Test
public void pageShouldHandleHtml() throws IOException {
    List<WebElement> elements = browser.findElements(By.xpath("//body//*"));
    assertThat(elements.size(), is(85));

    WebElement element = elements.get(0);

    Point location = element.getLocation();
    assertThat(location.getX(), is(255));
    assertThat(location.getY(), is(35));

    Dimension dimension = element.getSize();
    assertThat(dimension.getWidth(), is(879));
    assertThat(dimension.getHeight(), is(918));

    String tag = element.getTagName();
    assertThat(tag, is("div"));

    String txt = element.getText();
    assertThat(txt, is(nullValue()));/* www.ja  v a2 s.  c om*/

    String cssClass = element.getAttribute("class");
    assertThat(cssClass, is("page"));
}

From source file:com.smash.revolance.ui.model.element.api.Element.java

License:Open Source License

public static boolean isIncluded(WebElement element, Rectangle rectangle) {
    Point topleft = element.getLocation();
    Dimension dim = element.getSize();
    Rectangle rectangleRef = new Rectangle(topleft.getX(), topleft.getY(), dim.getWidth(), dim.getHeight());

    return rectangleRef.contains(rectangle);
}

From source file:com.smash.revolance.ui.model.element.api.ElementBean.java

License:Open Source License

public void setPos(Point pos) {
    if (pos != null) {
        this.x = pos.getX();
        this.y = pos.getY();
    }/* w  ww . ja v a 2  s.  c  o m*/
}

From source file:com.sugarcrm.candybean.examples.mobile.AppiumAndroidTest.java

License:Open Source License

@Test
public void testLocation() throws Exception {
    WebElement button = driver.findElement(By.xpath("//button[1]"));

    Point location = button.getLocation();

    assertEquals(location.getX(), 157);/*w ww  .  ja  v a 2  s.  c  o m*/
    assertEquals(location.getY(), 182);
}

From source file:com.sugarcrm.candybean.examples.mobile.AppiumIosTest.java

License:Open Source License

@Test
public void testLocation() throws Exception {
    WebElement button = driver.findElement(By.xpath("//button[1]"));

    Point location = button.getLocation();

    assertEquals(location.getX(), 94);/*from ww  w .  ja  v a  2  s.  c o  m*/
    assertEquals(location.getY(), 122);
}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

protected void mouseMove(WebElement elm) {
    Point coordinates = elm.getLocation();
    Robot robot;/*from  www.  java2  s  . c  o  m*/
    try {
        robot = new Robot();
        robot.mouseMove(coordinates.getX(), coordinates.getY() + 120);
    } catch (AWTException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.thoughtworks.selenium.webdriven.commands.GetElementPositionTop.java

License:Apache License

@Override
protected Number handleSeleneseCommand(WebDriver driver, String locator, String value) {
    Point location = finder.findElement(driver, locator).getLocation();
    return location.getY();
}

From source file:com.twiceagain.mywebdriver.driver.web.Drivers.java

License:Open Source License

/**
 * Screen shot of selected element only.
 *
 * @param wd//  w w  w  .ja v a 2s.  co m
 * @param ele
 * @return
 * @throws IOException
 */
public static File screenshot2TempFile(WebDriver wd, WebElement ele) throws IOException {
    Drivers.scrollElementIntoView(wd, ele);
    File fi = ((TakesScreenshot) wd).getScreenshotAs(OutputType.FILE);
    BufferedImage img = ImageIO.read(fi);
    // Get the location of element on the page
    Point point = ele.getLocation();

    // Get width and height of the element
    int eleWidth = ele.getSize().getWidth();
    int eleHeight = ele.getSize().getHeight();

    // Crop the entire page screenshot to get only element screenshot
    BufferedImage eleScreenshot = img.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
    ImageIO.write(eleScreenshot, "png", fi);
    return fi;
}

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

License:Open Source License

/**
 * Gets the cell element at the given cell address for the currently active
 * sheet. Throws NoSuchElementException if the cell is outside the visible
 * area.//from   ww  w . ja  v a 2s  .  c o  m
 * 
 * @param cellAddress
 *            Target address, e.g. A3
 * @return Cell element at the given index.
 * @throws NoSuchElementException
 *             if the cell at (cellAddress) is not found.
 */
public SheetCellElement getCellAt(String cellAddress) {
    Point point = AddressUtil.addressToPoint(cellAddress);
    return getCellAt(point.getY(), point.getX());
}