Supress printing (CTRL + P) dialog and set path and Save to PDF

235 views
Skip to first unread message

Bruno Tavares

unread,
May 6, 2021, 3:21:28 AM5/6/21
to Selenium Users
Hello, I am using ChromeDriver.
I would like to know how do I set the default download path and type (Save as PDF) when I send a print comand with selenium.

I'm using C#

var options = new ChromeOptionsWithPrefs();

options.AddArgument("--kiosk-printing");
options.AddArgument("--start-maximized");
options.prefs = new Dictionary<string, object>
{
{ "intl.accept_languages", "nl" },
{ "printing.print_preview_sticky_settings.appState", "{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"" },
};

var path = @"C:\teste\";

var driver = new ChromeDriver(path, options);

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("window.print();");






************************************************************************************************************************************************************************************************************
A informação transmitida nesta mensagem destina-se apenas à pessoa a qual foi endereçada, e pode conter informação confidencial, legalmente protegida e para conhecimento exclusivo do destinatário. É estritamente proibida a leitura, exame, retransmissão, divulgação, distribuição, cópia ou outro uso da mesma ou a tomada de qualquer ação baseada nesta informação por pessoas ou entidades que não sejam o destinatário. Caso esta mensagem tenha sido recebida por engano, por favor destrua-a e avise ao remetente por e-mail. Favor avisar imediatamente caso você ou seu empregador não permitam o recebimento de mensagens de e-Mail deste tipo. Os conceitos, conclusões e outras informações nesta mensagem que não relacionados aos negócios oficiais da minha empresa serão considerados como não fornecidos nem endossados por ela.

The information contained in this message is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should delete this message and kindly notify the sender by reply e-mail. Please advise immediately if you or your employer do not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of my firm shall be understood as neither given nor endorsed by it.
************************************************************************************************************************************************************************************************************
Reply all
Reply to author
Forward
0 new messages