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.
I prefer doing something like this :
1. Get the SRC attribute of the image. 2. Use ImageIO.read to read the image onto a BufferedImage 3. Save the BufferedImage using ImageIO.write function
For e.g.
String src = imgElement.getAttribute('src'); BufferedImage bufferedImage = ImageIO.read(new URL(src)); File outputfile = new File("saved.png"); ImageIO.write(bufferedImage, "png", outputfile);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With