小编Mav*_*ick的帖子

如何在C#中为Chlenium Grid 2的Chrome添加配置文件首选项?

这是我为Chrome进行本地自动测试运行和TeamCity(CI)添加配置文件首选项的方法:

Capabilities = DesiredCapabilities.Chrome();

var chromeOptions = new ChromeOptionsWithPrefs();
chromeOptions.AddUserProfilePreference("download.default_directory", DownloadPath);
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");

return new ChromeDriver(chromeDriverPath, chromeOptions);
Run Code Online (Sandbox Code Playgroud)

但是当我创建新的"RemoteWebDriver"时,我必须向它发送一个中心URL和"功能",这样我就可以将配置文件首选项发送到Firefox(到RemoteWebDriver):

var profile = new FirefoxProfile();

Capabilities = DesiredCapabilities.Firefox();

profile.SetPreference("browser.helperApps.alwaysAsk.force", false); 
profile.SetPreference("browser.download.useDownloadDir", true);
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.dir", DownloadPath);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk",
   "application/zip, application/octet-stream");

Capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());

return Capabilities;
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我,我需要像Chrome一样对Chrome做同样的事情.基本上我需要的是,我可以更改下载文件的默认路径.

c# selenium google-chrome selenium-grid2

3
推荐指数
1
解决办法
8444
查看次数

标签 统计

c# ×1

google-chrome ×1

selenium ×1

selenium-grid2 ×1