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.
my code:-
public static boolean search_camp() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Yukta Media\\selenium setup files\\chromedriver.exe");
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", "F:/innovid");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("port=3307");
chromeOptions.setExperimentalOption("prefs", chromePrefs);
WebDriver driver = new ChromeDriver(chromeOptions);
}