Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I was wondering, how can one use selenium/webdriver to download an image for a page. Assuming that the user session is required to download the image hence having pure URL is not helpful. Any sample code is highly appreciated.

1 Answer

0 votes
by (62.9k points)

You can use the below code:

   WebElement logo =   driver.findElement(By.cssSelector(".image-logo"));

 String logoSRC = logo.getAttribute("src");

 URL imageURL = new URL(logoSRC);

 BufferedImage saveImage = ImageIO.read(imageURL);

 ImageIO.write(saveImage, "png", new File("logo-image.png"));

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...