Road to capture clip of element locator in webdriver java

In this post I am going to show you how to capture clip of page element using webdriver.
Below I have written a ““java webdriver test script of a google application where I capture google menu clip and save into project.

package com.webdriver.test;

import java.awt.image.BufferedImage;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Point;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class CaptureElementClip {

        private WebDriver driver;
        private String baseUrl;

        public void setUp() throws Exception {
                    driver = new FirefoxDriver();
                    baseUrl = "";
                    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        public void testGoogle() throws IOException {

                    //open application url

                    //take screen shot
                    File screen = ((TakesScreenshot) driver)
                    //get webelement object of google menu locator
                    WebElement googleMenu = driver.findElement("gbz"));
                    Point point = googleMenu.getLocation();

                    //get element dimension
                    int width = googleMenu.getSize().getWidth();
                    int height = googleMenu.getSize().getHeight();
                    BufferedImage img =;
                    BufferedImage dest = img.getSubimage(point.getX(), point.getY(), width,
                    ImageIO.write(dest, "png", screen);
                    File file = new File("Menu.png");
                    FileUtils.copyFile(screen, file);

          public void tearDown() throws Exception {

After executing above test a “Menu.png” file is generated in root folder of your project.


  1. I have a below questions could any one answer –
    1. I have three browsers in first browser that is in IE I have entered the data and submitted after submit popup window displayed in which some data is there so capture that data and save now in second Brower that is chrome enter data and submit after submit popup window displayed in which some data is there so capture that data. In in third browser the first two browsers data need to be entered.
    Could anyone write the script for this?

    2. How to handle windows using Java script for attaching a file in Gmail compose without using sikuli or AutoIt.

  2. u should switch to pop up window then select the text..

  3. You can use the Robot Class to handle the Attaching file in email.


Leave your comments, queries, suggestion I will try to provide solution