Java Code Examples for org.openqa.selenium.WebElement#getSize()

The following examples show how to use org.openqa.selenium.WebElement#getSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void mark(WebElement ele, File file) throws IOException
{
	BufferedImage bufImg = ImageIO.read(file);
	
	try
	{
		WebElement webEle = (WebElement) ele;
		Point loc = webEle.getLocation();
		Dimension size = webEle.getSize();
		
		Graphics2D g = bufImg.createGraphics();
		g.setColor(Color.red);
		g.drawRect(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
	}
	catch(StaleElementReferenceException se)
	{
	}
}
 
Example 2
Source Project: opentest   File: ReadElementAspect.java    License: MIT License 6 votes vote down vote up
@Override
public void run() {
    super.run();
    
    By locator = this.readLocatorArgument("locator");

    WebElement element = this.getElement(locator);
    Point point = element.getLocation();

    int x = point.getX();
    int y = point.getY();

    Dimension size = element.getSize();
    int width = size.width;
    int height = size.height;

    this.writeOutput("x", x);
    this.writeOutput("y", y);
    this.writeOutput("width", width);
    this.writeOutput("height", height);
}
 
Example 3
private void clickAt( WebElement webElement, WebDriver webDriver, int x, int y )
{
    if ( webElement != null )
    {

        Dimension elementSize = webElement.getSize();

        int useX = (int) ((double) elementSize.getWidth() * ((double) x / 100.0)) + webElement.getLocation().getX();
        int useY = (int) ((double) elementSize.getHeight() * ((double) y / 100.0)) + webElement.getLocation().getY();


        if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof AppiumDriver )
        {
            new TouchAction( (AppiumDriver) ((DeviceWebDriver) webDriver).getNativeDriver() ).press( PointOption.point( useX, useY ) ).perform();
        }
        else if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof RemoteWebDriver )
        {
            if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof HasTouchScreen )
                new TouchActions( webDriver ).move( useX, useY ).click().build().perform();
            else
                new Actions( webDriver ).moveByOffset(useX,  useY ).click().build().perform();
        }

    }
}
 
Example 4
@Override
public void mouseMoveOut() throws WidgetException {
	try {
        // TODO: Need to figure out whether 10 is sufficient
        int offsetAmount = 10;

        WebElement elem = getWebElement();
        Dimension dim = elem.getSize();
        int width = dim.getWidth();
        Actions builder = new Actions(getGUIDriver().getWrappedDriver());
        synchronized (InteractiveElement.class) {
            getGUIDriver().focus();
            builder.moveToElement(getWebElement(), width + offsetAmount, 0).build().perform();
        }
	} catch (Exception e) {
		throw new WidgetException("Error while performing mouse move out",
				getByLocator(), e);
	}
}
 
Example 5
@Override
public void addAnnotationData(Map<String, Object> data, WebElement webElement) {
    Point location = webElement.getLocation();
    Dimension size = webElement.getSize();

    data.put("x", location.getX());
    data.put("y", location.getY());
    data.put("width", size.getWidth());
    data.put("height", size.getHeight());
}
 
Example 6
@Step
@When("установить пикер в первое значение")
public void setFirstPickerWheelValue() {
    WebElement webElement = driver.findElement(By.xpath(pickerWheelXPath));
    Point center = ((IOSElement) webElement).getCenter();
    Dimension size = webElement.getSize();
    int height = size.getHeight();
    Point target = new Point(center.getX(), center.getY() - (int) (height * stepToLast));
    TouchAction touchAction = new TouchAction(driver);
    touchAction.press(point(target.getX(), target.getY())).release();
    touchAction.perform();
}
 
Example 7
@Step
@When("установить пикер в последнее значение")
public void setLastPickerWheelValue() {
    WebElement webElement = driver.findElement(By.xpath(pickerWheelXPath));
    Point center = ((IOSElement) webElement).getCenter();
    Dimension size = webElement.getSize();
    int height = size.getHeight();
    Point target = new Point(center.getX(), center.getY() + (int) (height * stepToLast));
    TouchAction touchAction = new TouchAction(driver);
    touchAction.press(point(target.getX(), target.getY())).release();
    touchAction.perform();
}
 
Example 8
@Test
@NotYetImplemented(HTMLUNIT)
public void testMovingMouseToRelativeElementOffset() {
  driver.get(pages.mouseTrackerPage);

  WebElement trackerDiv = driver.findElement(By.id("mousetracker"));
  Dimension size = trackerDiv.getSize();
  new Actions(driver).moveToElement(trackerDiv, 95 - size.getWidth() / 2, 195 - size.getHeight() / 2).perform();

  WebElement reporter = driver.findElement(By.id("status"));

  wait.until(fuzzyMatchingOfCoordinates(reporter, 95, 195));
}
 
Example 9
@Test
@NotYetImplemented(HTMLUNIT)
public void testMovingMouseToRelativeZeroElementOffset() {
  driver.get(pages.mouseTrackerPage);

  WebElement trackerDiv = driver.findElement(By.id("mousetracker"));
  new Actions(driver).moveToElement(trackerDiv, 0, 0).perform();

  WebElement reporter = driver.findElement(By.id("status"));

  Dimension size = trackerDiv.getSize();
  wait.until(fuzzyMatchingOfCoordinates(reporter, size.getWidth() / 2, size.getHeight() / 2));
}
 
Example 10
@Override
public void hover(Element ele)
{
	WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele);
	if(webEle == null)
	{
		logger.warn("can not found element.");
		return;
	}
	
	if(!(ele instanceof FileUpload))
	{
		Dimension size = webEle.getSize();
		Point loc = webEle.getLocation();
		int toolbarHeight = engine.getToolbarHeight();
		int x = size.getWidth() / 2 + loc.getX();
		int y = size.getHeight() / 2 + loc.getY() + toolbarHeight;
		
		try
		{
			new Robot().mouseMove(x, y);
		}
		catch (AWTException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
Example 11
Source Project: marathonv5   File: JavaDriverTest.java    License: Apache License 2.0 5 votes vote down vote up
public void getSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    Dimension size = element1.getSize();
    java.awt.Dimension d = EventQueueWait.call(button, "getSize");
    AssertJUnit.assertEquals(d.width, size.width);
    AssertJUnit.assertEquals(d.height, size.height);
}
 
Example 12
Source Project: selenium-shutterbug   File: Coordinates.java    License: MIT License 5 votes vote down vote up
public Coordinates(WebElement element, Double devicePixelRatio) {
    Point point = element.getLocation();
    Dimension size = element.getSize();
    this.width = (int)(size.getWidth()*devicePixelRatio);
    this.height = (int)(size.getHeight()*devicePixelRatio);
    this.x = (int)(point.getX()*devicePixelRatio);
    this.y = (int)(point.getY()*devicePixelRatio);
}
 
Example 13
Source Project: find   File: SunburstView.java    License: MIT License 5 votes vote down vote up
private void specialHover(final WebElement segment) {
    final Dimension dimensions = segment.getSize();

    DriverUtil.hoveringOffSide(segment, new Point(dimensions.getWidth() / 4 * 3, dimensions.getHeight() / 2), getDriver());
    if (!sunburstCentreHasText() || sunburstCentreHasText() && "Parametric Distribution".equals(getSunburstCentreName())) {
        DriverUtil.hoveringOffSide(segment, new Point(dimensions.getWidth() / 4, dimensions.getHeight() / 2), getDriver());
    }
}
 
Example 14
@Test
@Ignore(value = MARIONETTE, issue = "https://github.com/mozilla/geckodriver/issues/789")
@NotYetImplemented(HTMLUNIT)
@NotYetImplemented(SAFARI)
@NotYetImplemented(EDGE)
public void testMoveMouseByOffsetOverAndOutOfAnElement() {
  driver.get(pages.mouseOverPage);

  WebElement greenbox = driver.findElement(By.id("greenbox"));
  WebElement redbox = driver.findElement(By.id("redbox"));
  Point greenboxPosition = greenbox.getLocation();
  Point redboxPosition = redbox.getLocation();
  int shiftX = redboxPosition.getX() - greenboxPosition.getX();
  int shiftY = redboxPosition.getY() - greenboxPosition.getY();

  Dimension greenBoxSize = greenbox.getSize();
  int xOffset = 2 - greenBoxSize.getWidth() / 2;
  int yOffset = 2 - greenBoxSize.getHeight() / 2;

  new Actions(driver).moveToElement(greenbox, xOffset, yOffset).perform();

  shortWait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));

  new Actions(driver).moveToElement(greenbox, xOffset, yOffset)
    .moveByOffset(shiftX, shiftY).perform();
  shortWait.until(attributeToBe(redbox, "background-color", Colors.RED.getColorValue().asRgba()));

  new Actions(driver).moveToElement(greenbox, xOffset, yOffset)
    .moveByOffset(shiftX, shiftY)
    .moveByOffset(-shiftX, -shiftY).perform();

  shortWait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
}
 
Example 15
Source Project: webtau   File: ImageAnnotation.java    License: Apache License 2.0 4 votes vote down vote up
protected Point center(WebElement webElement) {
    Point location = webElement.getLocation();
    Dimension size = webElement.getSize();

    return new Point(location.getX() + size.getWidth() / 2, location.getY() + size.getHeight() / 2);
}
 
Example 16
Source Project: selenium   File: GetElementSize.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Dimension call() {
  WebElement element = getElement();
  return element.getSize();
}
 
Example 17
Source Project: opentest   File: AssertElementImage.java    License: MIT License 4 votes vote down vote up
/**
 * Capture the image of the target HTML element.
 * @param targetLocator The locator of the HTML element to capture.
 * @param ignoredElements The HTML elements ignored from the comparison.
 * @param scaleFactor For retina displays, this has to be set to 2.
 * @param ignoredPixelsColor The color that will be used to obscure the
 * HTML elements that are ignored from the comparison.
 * @return The image of the HTML element.
 */
private BufferedImage captureImage(By targetLocator, By[] ignoredElements, Double scaleFactor, Color ignoredPixelsColor) {
    WebElement targetElement = this.getElement(targetLocator);
    ShootingStrategy shootingStrategy = ShootingStrategies.viewportPasting(ShootingStrategies.scaling(scaleFactor.floatValue()), 100);
    AShot ashot = new AShot()
            .coordsProvider(new WebDriverCoordsProvider())
            .shootingStrategy(shootingStrategy);

    // Hide scroll bars, so they don't impact the captured image
    JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
    Object overflowValue = jsExecutor.executeScript("return document.querySelector('html').style.overflow");
    if (!(overflowValue instanceof String)) {
        overflowValue = "initial";
    }
    jsExecutor.executeScript("document.querySelector('html').style.overflow = 'hidden'");

    Screenshot screenshot = ashot.takeScreenshot(driver, targetElement);
    BufferedImage capturedImage = screenshot.getImage();

    jsExecutor.executeScript(String.format("document.querySelector('html').style.overflow = '%s';", overflowValue));

    for (By by : ignoredElements) {
        Point targetElemLocation = targetElement.getLocation();

        WebElement ignoredElement = this.getElement(by);
        Point ignoredElementLocation = ignoredElement.getLocation();

        Dimension size = ignoredElement.getSize();
        int width = size.width;
        int height = size.height;

        int relativeX = ignoredElementLocation.getX() - targetElemLocation.getX();
        int relativeY = ignoredElementLocation.getY() - targetElemLocation.getY();

        for (int xCoord = relativeX; xCoord < relativeX + width; xCoord++) {
            for (int yCoord = relativeY; yCoord < relativeY + height; yCoord++) {
                capturedImage.setRGB(xCoord, yCoord, ignoredPixelsColor.getRGB());
            }
        }
    }

    return capturedImage;
}
 
Example 18
Source Project: blueocean-plugin   File: SmartWebElement.java    License: MIT License 4 votes vote down vote up
@Override
public Dimension getSize() {
    WebElement e = getElement();
    return e.getSize();
}
 
Example 19
@Override
protected Dimension _getSize()
{
  WebElement webElement = getElement();
  return webElement.getSize();
}
 
Example 20
Source Project: find   File: SunburstView.java    License: MIT License 4 votes vote down vote up
public void hoverOverTooFewToDisplaySegment() {
    final WebElement areaWithGrey = findElement(By.cssSelector("svg > path[fill='#f0f0f0']"));
    final Dimension dimensions = areaWithGrey.getSize();

    DriverUtil.hoveringOffSide(areaWithGrey, new Point(dimensions.getWidth() / 6, dimensions.getHeight() / 2), getDriver());
}