Java Code Examples for org.openqa.selenium.WebElement.getLocation()

The following are Jave code examples for showing how to use getLocation() of the org.openqa.selenium.WebElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: phoenix.webui.framework   File: TargetElementMark.java   Source Code and License Vote up 6 votes
@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
Project: marathonv5   File: JavaDriverTest.java   Source Code and License Vote up 6 votes
public void getLocation() 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"));
    Point location = element1.getLocation();
    java.awt.Point p = EventQueueWait.call(button, "getLocation");
    AssertJUnit.assertEquals(p.x, location.x);
    AssertJUnit.assertEquals(p.y, location.y);
}
 
Example 3
Project: phoenix.webui.framework   File: SeleniumHover.java   Source Code and License Vote up 5 votes
@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 4
Project: ats-framework   File: MobileElement.java   Source Code and License Vote up 5 votes
/**
 * Scroll to element (at the center of the screen)
 *
 * @return this mobile element which allows chained actions
 */
@SuppressWarnings( "unchecked")
@PublicAtsApi
public T scrollTo() {

    try {

        if (MobileElementFinder.getElementContext(this).toUpperCase().startsWith("WEBVIEW")) {

            // in WEBVIEWs the target element exists, while in the NATIVE context it doesn't until we scroll to it
            new MobileElementState(this).waitToBecomeExisting();

            Dimension screenDimensions = ((MobileDriver) getUiDriver()).getScreenDimensions();
            WebElement element = MobileElementFinder.findElement(appiumDriver, this);

            // window.scrollTo(0, element.getLocation().y);    -->  will scroll the element to top-left

            int scrollToY = 0;
            int screenCenter = screenDimensions.getHeight() / 2 + element.getSize().height / 2;
            if (element.getLocation().y < screenCenter) {
                // the element is located after the screen center if we scroll to (0, element.getLocation().y)
                // because it is near the bottom of the application => we can't center it, but it is OK on that position
                scrollToY = element.getLocation().y;
            } else {
                scrollToY = element.getLocation().y - screenCenter;
            }

            ((JavascriptExecutor) appiumDriver).executeScript("window.scrollTo(0," + scrollToY + ")");
        } else {

            if (getElementProperty("name") != null) {
                appiumDriver.scrollTo(getElementProperty("name")); // only works for NATIVE context
            }
        }

        return (T) this;
    } catch (Exception e) {
        throw new MobileOperationException(this, "scrollTo", e);
    }
}
 
Example 5
Project: twitter-stuff   File: StatusUtils.java   Source Code and License Vote up 5 votes
public static void takeStatusScreenshot(Status status, MongoDatabase mongoDatabase, WebDriver driver) {
    long id = status.getId();
    User user = status.getUser();
    try {
        // visit the twitter url
        driver.get(TWITTER_BASE_URL + user.getScreenName() + "/status/" + id);

        WebDriverWait webDriverWait = new WebDriverWait(driver, 4);
        webDriverWait.until(
                ExpectedConditions.visibilityOfElementLocated(
                        By.cssSelector(PERMALINK_TWEET_CONTAINER)));

        // Find the tweet container
        WebElement element = driver.findElement(By.cssSelector(PERMALINK_TWEET_CONTAINER));

        // take a full screenshot
        File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

        // create in memory image data
        BufferedImage screenshotImage = ImageIO.read(screenshotFile);

        // calculate the position of the tweet element
        Point point = element.getLocation();
        int elementWidth = element.getSize().getWidth();
        int elementHeight = element.getSize().getHeight();

        // crop to get only the container of the tweet itself (sometimes this doesn't work on mac)
        BufferedImage elementScreenshotImage =
                screenshotImage.getSubimage(
                        point.getX() + 4,
                        point.getY() + 4,
                        elementWidth - 4,
                        screenshotImage.getHeight() < point.getY() + elementHeight
                                ? screenshotImage.getHeight() - 4
                                : elementHeight - 4);
        ImageIO.write(elementScreenshotImage, "png", screenshotFile);
        FileUtils.copyFile(screenshotFile, new File("screenshot/" + id + ".png"));
    } catch (Exception e) {
        saveFailureStatusProcesssed(mongoDatabase, id, false);
        System.out.println(
                String.format(
                        "Unable to create screenshot for %s with id: %d",
                        user.getScreenName(),
                        id));
        e.printStackTrace();
    }
}
 
Example 6
Project: creative-element   File: CreativeElement.java   Source Code and License Vote up 4 votes
public CreativeElement(WebElement e){
    this.element = e;
    this.quad = new CyclicQuad(e.getLocation(), e.getSize().getHeight(), e.getSize().getWidth());
}