File download automation not working in headless mode with ChromeDriver (Java & Selenium )

497 views
Skip to first unread message

Anjum Sawnoorkar

unread,
Jan 18, 2018, 6:17:42 AM1/18/18
to Selenium Users

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);

}

Chrome error.txt

Anjum Sawnoorkar

unread,
Jan 22, 2018, 3:31:25 AM1/22/18
to Selenium Users
if anyone knows the solution
Reply all
Reply to author
Forward
0 new messages