To preface, I cannot run in --headless
mode because I unfortunately need to get a file to download, and using ChromeDriver without --headless
is the only way I can get it to work. The script runs fine manually, and also runs fine when scheduled and logged in, but it failed when scheduled and the screen was locked/user logged out.
I ideally want this to be able to run while logged out but still have access to the default ChromeDriver behavior that exists when I'm logged in/unlocked. I have a bad feeling this isn't possible because it seems as though the non-headless version depends on a graphics input, but I'm hoping I'm wrong. Again, the file download is the main constraint here, otherwise I would just use HTMLUnitDriver
.
Here is my driver configuration for reference:
//browser prefs
HashMap<String, Object> preferences = new HashMap<>();
preferences.put("profile.default_content_settings.popups", 0);
preferences.put("download.default_directory", downloadPath);
//browser options config
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
//add capabilities to options
options.merge(cap);
WebDriver driver = new ChromeDriver(options);
I'm using the newest version of chromedriver.exe
.