Let me begin by saying I have tried suggestions from the following linked Stack Overflow articles to no avail:
This one is most similar to my problem and has no answer Downloading PDF using Selenium Java not working in Chrome
How to download a pdf file in chrome using selenium webdriver
Here is what I have for my ChromeOptions:
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
chromeOptions.AddUserProfilePreference("download.default_directory", DOWNLOAD_DIR);
//chromeOptions.AddUserProfilePreference("disable-popup-blocking", true);
chromeOptions.AddUserProfilePreference("plugins.plugins_disabled", "Chrome PDF Viewer");
chromeOptions.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
chromeOptions.AddArgument("--no-sandbox");
_driver = new ChromeDriver(chromeOptions);
}
You'll notice the ("disable-popup-blocking", true) bit is commented out, and this is because it took me from seeing this:
back to the PDF desired for download appearing.
Like all of the above linked posts, I need to download the PDF when I click the link to it instead of opening it in a new window, and because of Selenium's limitations with PDFs, I have not been able to successfully click the "Open" button on the disabled viewer. Visual Studio throws the following exception:
As requested in the comments, here's the code attempting to interact with the disabled PDF viewer:
_driver.SwitchTo().Window(_driver.WindowHandles[1]);
_driver.FindElement(By.LinkText("Open")).Click();
Does anyone have any possible solutions or insight into what is going on here? I'm still relatively new to programming and would appreciate any advice.
In case it's at all relevant, the PDF I'm attempting to download is a Salesforce Lightning PDF