Unable to change Printer value to “Save as PDF” in edge using selenium

Saurav Guha 1 Reputation point
2021-07-23T14:51:10.127+00:00

I am trying to download a web page as pdf using edgewebdriver and selenium. Now, the edge is configured to a OneNote(Desktop)

I want to change the dropdown value in the dialog before clicking on the print button. This is the constructor code where I am initializing the driver

public Driver(bool headLess = true)
{
var driverPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Driver");
var chromeDriverService = EdgeDriverService.CreateChromiumService(driverPath);
chromeDriverService.HideCommandPromptWindow = true;
var edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
var appState = new AppState()
{
recentDestinations = new List<RecentDestination>()
{
new RecentDestination(){ id = "Save as PDF", origin ="local", account = ""}
},
selectedDestinationId = "Save as PDF",
version = 2
};
edgeOptions.AddUserProfilePreference("printing.print_preview_sticky_settings", appState);
edgeOptions.AddArguments("kiosk-printing");
if (headLess)
{
edgeOptions.AddArgument("headless");
}
this._driver = new EdgeDriver(chromeDriverService, edgeOptions);
}

I have referred the following link https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/pref_names.cc

I am totally stuck and can't find any solution to the problem. Every time "Print" dialog comes but the it tries to save to OneNode(Desktop).

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,311 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.