Back
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.
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"));
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