RE: How to download the all images from Website Using selenium webdriver tool

I was written below script that is not working in properly? Please help me?

package getAllImages;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Read_Images {
WebDriver driver;
public void GetBrowser()
driver = new FirefoxDriver();
public void End()
public void getImage() throws Exception
File files = null;
int loop= 0;

List <WebElement> Images = driver.findElements(By.tagName(“img”));
System.out.println(“No_Of Images:” +Images.size());

for(WebElement img :Images)

// Get the all images name and display;

String[] name = img.getAttribute(“src”).split(“/”);
String ImgName = name[name.length-1];

// Save the all Images:

URL imag = new URL(img.getAttribute(“src”).trim());
files = new File(“D:\\TEMP\\”+ System.currentTimeMillis()+ “.” +ImgName);, files);
System.out.println(“No_of Total downloaded images is :”+loop);

If I Run this code i got below error,

D:\TEMP\1461562718829.Damden-Vivo-Thumbnail_2.jpg?1455952362 (The filename, directory name, or volume label syntax is incorrect)

My doubt is,
what is the error, and why it is occur?

jakay Default Asked on April 25, 2016 in Selenium WebDriver.
Add Comment
1 Answers

ImgName= 1461562718829.Damden-Vivo-Thumbnail_2.jpg?1455952362

You image name should not contain ‘?’ mark. Please look where it is coming from and resolve it.

Note: A filename cannot contain any of the following characters:

\ / : * ? ” < > |
Train Answered on May 3, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.