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

The following examples show how to use org.openqa.selenium.WebElement#getSize() . 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 check out the related API usage on the sidebar.
Example 1
Source File: TargetElementMark.java    From phoenix.webui.framework with Apache License 2.0 7 votes vote down vote up
@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 File: InteractiveElement.java    From JTAF-ExtWebDriver with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: NumberPickerSetMethod.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: ReadElementAspect.java    From opentest with 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 5
Source File: BasicMouseInterfaceTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: SunburstView.java    From find with 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 7
Source File: Coordinates.java    From selenium-shutterbug with 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 8
Source File: JavaDriverTest.java    From marathonv5 with 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 9
Source File: SeleniumHover.java    From phoenix.webui.framework with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: BasicMouseInterfaceTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: BasicMouseInterfaceTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: BaseIOSPickerWheelSteps.java    From colibri-ui with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: BaseIOSPickerWheelSteps.java    From colibri-ui with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: RectangleBasedImageAnnotation.java    From webtau with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: AssertElementImage.java    From opentest with 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 16
Source File: SmartWebElement.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public Dimension getSize() {
    WebElement e = getElement();
    return e.getSize();
}
 
Example 17
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Dimension _getSize()
{
  WebElement webElement = getElement();
  return webElement.getSize();
}
 
Example 18
Source File: GetElementSize.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public Dimension call() {
  WebElement element = getElement();
  return element.getSize();
}
 
Example 19
Source File: SunburstView.java    From find with 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());
}
 
Example 20
Source File: ImageAnnotation.java    From webtau with 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);
}