Re: Save image to desire location

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Save image to desire location

Venugopal Gadiparthi


Hi Manoj,
Instead of taking screenshot  and crop from local system. Image available on the web page. We need to crop it while traversing to the application. How to do it?
Please find the below screenshot. 
Any suggestion?



  

On Tuesday, November 27, 2012 at 1:32:47 PM UTC+5:30, Manoj Hans wrote:
Hi folks,

I m just sharing the code for saving image to desire location may be it will help many of u.

DownloadImage(By.xpath("//*[@id='content']/div/div[1]/div/div/div[1]/img"),
"D:\\Download\\image.png");

public void DownloadImage(By by,String loc) throws IOException{
WebElement Image=driver.findElement(by);
File screen=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        int width=Image.getSize().getWidth();
        int height=Image.getSize().getHeight();
        BufferedImage img=ImageIO.read(screen);
        BufferedImage dest=img.getSubimage(Image.getLocation().getX(), Image.getLocation().getY(), width, height);
        ImageIO.write(dest, "png", screen);
        File file=new File(loc);
         FileUtils.copyFile(screen,file);
}



--Manoj Hans

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a2684029-0964-405e-be9a-ef9bc8bccf53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.