How to implement a screenshot of a region in Webdriver and how to capture a picture in a frame

Source: Internet
Author: User

Import Java.awt.Rectangle;
Import Java.awt.image.BufferedImage;
Import Java.io.File;
Import java.io.IOException;
Import Javax.imageio.ImageIO;
Import Org.apache.commons.io.FileUtils;
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;
public class Screenshot {
public void Screenshotforelement (Webdriver driver,webelement element, String path,int X,int y) throws Interruptedexcepti on {
Capture a picture of the entire page
File Scrfile = ((takesscreenshot) driver). Getscreenshotas (Outputtype.file);
try {
Gets the position object in the frame where the element is located
Point P = element.getlocation ();
Gets the width and height of the element
int width = element.getsize (). GetWidth ();
int height = element.getsize (). GetHeight ();
Rectangle Image Object
Rectangle rect = new Rectangle (width, height);
BufferedImage img = imageio.read (scrfile);
X, y to add the left margin of the current frame, top margin
BufferedImage dest = Img.getsubimage (P.getx () +x, p.gety () +y,rect.width, rect.height);
Imageio.write (dest, "PNG", scrfile);
Fileutils.copyfile (Scrfile, new File (path));
} catch (IOException e) {
E.printstacktrace ();
}
}

}

How to implement regions in Webdriver and how to intercept pictures in a frame

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.