Hey Uday, you can write following lines of code to download any file in chrome or mozilla using selenium webdriver:
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class DownloadPDF {
static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", chrome_driver_path);
String downloadFilePath = "C:\\Users\\Prati_R\\Downloads\\PDFDownloads";
HashMap<String, Object> chromePref = new HashMap<String, Object>();
chromePref.put("profile.default_content_settings.popups", 0);
chromePref.put("download.default_directory", downloadFilePath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePref);
driver = new ChromeDriver(options);
driver.get("https://www.seleniumhq.org/download/");
driver.findElement(By.xpath("//*[@id=\"mainContent\"]/p[7]/a[1]")).click();
Thread.sleep(3000);
driver.close();
}
}