• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because you are relying on browser behavior to automatically download. With a headless browser, I think you'd have to call driver.getPageSource() and write that to a file.


Also, consider making your code more robust by adding checks for waits:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic