C # Selenium ChromeDriver - How to Suppress Preview, pdf

I know there are many such questions, but there is nothing from my research that solves the problem of suppressing PDF viewing in Chrome with the current C # Chromedriver state.

I can get the test to work manually by disabling the Chrome PDF Viewer plugin and doing -disable-print-preview on the command line, but I was unable to get anything to work in Selenium.

I've tried chromeOptions.AddUserProfilePreference ("plugins.plugins_disabled", "Chrome PDF Viewer"); chromeOptions.AddArgument ("- disable print preview");

and many more options including adding download.default_directory, suppressing download.prompt_for_download, etc.

The constructor for ChromeDriver that used Capabilities no longer works. Also, everyone else talking about PDFs wants the preview to happen in a tab, opposite of what I want. I would like the PDF to load in the same way as when manually disabling the plugin.

+3


source to share


1 answer


I found a working solution



var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("plugins.plugins_disabled", new[] {
                "Adobe Flash Player",
                "Chrome PDF Viewer"
            });
var driver = new ChromeDriver(path + @"\chrome-driver", chromeOptions);

      

+1


source







All Articles