How to Set Chrome Preferences Using Selenium Webdriver .Net Binding

How to set Chrome preferences using Selenium Webdriver .NET binding?

The Selenium dotNet driver does not support setting the chrome.prefs out of the box. The problem is that chrome.prefs must be defined as prefs under the chromeOptions node. The ChromeOptions class does not contain this variable, so you'll need to create your own ChromeOptions class:

public class ChromeOptionsWithPrefs: ChromeOptions
{
public Dictionary<string,object> prefs { get; set; }
}

public static void Initialize()
{
var options = new ChromeOptionsWithPrefs();
options.prefs = new Dictionary<string, object>
{
{ "intl.accept_languages", "nl" }
};
_driver = new ChromeDriver(@"C:\path\chromedriver", options);
}

How to set Chrome experimental option in C# Selenium?

In case anyone stumbles upon this looking for the answer like I did...

The way to do this is

ChromeOptions options = new ChromeOptions();
options.AddLocalStatePreference("browser", new { enabled_labs_experiments = new string[] { "http-auth-committed-interstitials@2" } });

The value is normally read from the LocalState file in your UserData directory. In the above code example the value you are trying to set is placed in the string array in the form of "value@option" where 'value' is the name of the experimental feature and 'option' is either 1 for enable, or 2 for disabled.

How to execute Selenium Chrome WebDriver in silent mode?

I simply do this

ChromeOptions options = new ChromeOptions();
options.AddArgument("--log-level=3");
IWebDriver driver = new ChromeDriver(options);

C# Set default download directory chrome WebDriver?

Just pasting the answer that OP found, but did not add as an answer.

var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", @"D:\DataTest");
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
var driver = new ChromeDriver(@"D:\chromedriver_win32\", chromeOptions);
var download = driver.FindElements(By.XPath("//a[.='ダウンロード']"));

foreach (var t in download)
{
t.SendKeys(Keys.Enter);
}

Disable images in Selenium Google ChromeDriver

Use http://chrome-extension-downloader.com/ to download the "Block Image" extension (https://chrome.google.com/webstore/detail/block-image/pehaalcefcjfccdpbckoablngfkfgfgj?hl=en-GB). The extension prevents the image from being downloaded in the first place. Now it's just a matter of loading it using the following statement:

    var options = new ChromeOptions();

//use the block image extension to prevent images from downloading.
options.AddExtension("Block-image_v1.0.crx");

var driver = new ChromeDriver(options);

How to set up performance logging in SeleniumWebdriver with Chrome

Edit 2022:
ChromePerformanceLoggingPreferences was removed so this solution will not work for recent versions.

Deprecated answer:

Not sure what is wrong with your example, but this worked for me:

var options = new ChromeOptions();
var perfLogPrefs = new ChromePerformanceLoggingPreferences();
var tracingCategories = "toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark";
perfLogPrefs.AddTracingCategories(new string[] { tracingCategories });
options.PerformanceLoggingPreferences = perfLogPrefs;
options.SetLoggingPreference("performance", LogLevel.All);

var Driver = new ChromeDriver(options);

This is how you get the logs afterwards:

var logs = Driver.Manage().Logs.GetLog("performance");

There was a bug in selenium that was fixed in version 3.14 that wouldn't allow this to work. If you're getting a "unrecognized performance logging option: enableTimeline" error try updating selenium.

Download MP4 file instead of playing it using ChromeDriver?

ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", getClass().getResource("/data/input").toString().replace("%20", " ").replace("file:","").replaceFirst("/", ""));
options.setExperimentalOption("prefs", prefs);

options.addArguments("--test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);


Related Topics



Leave a reply



Submit