I want to download a file from a website in headless mode using Selenium in Java. The code works fine without headless mode and file gets downloaded to downloads folder on the machine. But when I try to use headless mode, the file does not get downloaded somehow. Also, the program does not show any error or exception.
Below is the code. When I comment the statement 'options.addArguments("headless");' , Chrome browser opens the website and clicks the required buttons to download the file. But , I want to use the headless mode only. Please help.
File file = new
File(StackApplicationDownloader.class.getClassLoader().getResource("driver/chromedriver.exe").getFile());
StackApplicationDownloader.class.getClassLoader().getResource("driver/chromedriver.exe").getFile();
String driverPath=file.getAbsolutePath();
System.out.println("Webdriver is in path: "+driverPath);
System.setProperty("webdriver.chrome.driver",driverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1200x600");
WebDriver driver = new ChromeDriver(options);
driver.navigate().to("https://340bopais.hrsa.gov/reports");
driver.findElement(By.xpath("//*[@id=\"headingTwo\"]/h4/a")).click();
driver.findElement(By.xpath("//*[@id=\"ContentPlaceHolder1_lnkCEDailyReport\"]")).click();
System.out.println("Done");