Refine search
/** * Method returns central coordinates of an element. * @return The instance of the {@link org.openqa.selenium.Point} */ public Point getCenter() { Point upperLeft = this.getLocation(); Dimension dimensions = this.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); }
WebDriver adjustBrowserPosition(Config config, WebDriver driver) { if (config.browserPosition() != null) { log.info("Set browser position to " + config.browserPosition()); String[] coordinates = config.browserPosition().split("x"); int x = Integer.parseInt(coordinates[0]); int y = Integer.parseInt(coordinates[1]); Point target = new Point(x, y); Point current = driver.manage().window().getPosition(); if (!current.equals(target)) { driver.manage().window().setPosition(target); } } return driver; }
@Override public WebElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { Point location = locator.getWebElement().getLocation(); locator.driver().executeJavaScript("window.scrollTo(" + location.getX() + ", " + location.getY() + ')'); return proxy; } }
java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); org.openqa.selenium.Point position = new Point(0, 0); driver.manage().window().setPosition(position); org.openqa.selenium.Dimension maximizedScreenSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()); driver.manage().window().setSize(maximizedScreenSize);
@Override public int getTop() { return getElement().getLocation().getY(); }
@Override public int getLeft() { return getElement().getLocation().getX(); }
/** * It defines x and y coordinates. * This is offset from the upper left corner of the screen. * * @param xOffset is x value. * @param yOffset is y value. * @return self-reference */ public T withCoordinates(int xOffset, int yOffset) { coordinates = new Point(xOffset, yOffset); //noinspection unchecked return (T) this; }
public Point call() throws Exception { currentLocation = element.getLocation(); if (currentLocation.equals(expectedLocation)) { return expectedLocation; } return null; }
public Point getLocation() { if(is_not_null(_webElement)) { Point value = _webElement.getLocation(); info("Element '" + super.name() + "' - Location is '" + value + "'"); return value; } else { info("Element '" + super.name() + "' - has a null _webelement, cannot do getLocation()"); } return new Point(0, 0); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Locations other = (Locations) obj; if (!this.topLeft.equals(other.topLeft)) { return false; } if (!this.topRight.equals(other.topRight)) { return false; } if (!this.bottomLeft.equals(other.bottomLeft)) { return false; } if (!this.bottomRight.equals(other.bottomRight)) { return false; } return true; }
private BufferedImage takeScreenshotAsImage(WebDriver webdriver, WebElement element) { if (!(webdriver instanceof TakesScreenshot)) { log.warning("Cannot take screenshot because browser does not support screenshots"); return null; } byte[] screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.BYTES); Point elementLocation = element.getLocation(); try { BufferedImage img = ImageIO.read(new ByteArrayInputStream(screen)); int elementWidth = element.getSize().getWidth(); int elementHeight = element.getSize().getHeight(); if (elementWidth > img.getWidth()) { elementWidth = img.getWidth() - elementLocation.getX(); } if (elementHeight > img.getHeight()) { elementHeight = img.getHeight() - elementLocation.getY(); } return img.getSubimage(elementLocation.getX(), elementLocation.getY(), elementWidth, elementHeight); } catch (IOException e) { log.log(SEVERE, "Failed to take screenshot of " + element, e); return null; } catch (RasterFormatException e) { log.warning("Cannot take screenshot because element is not displayed on current screen position"); return null; } }
public SelenideElement scrollTo() { Point location = getWebElement().getLocation(); jsExecutor().executeScript("window.scrollTo(" + location.getX() + ", " + location.getY() + ')'); return this; }