Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中为Selenium Grid 2的Chrome添加配置文件首选项?_C#_Google Chrome_Selenium_Selenium Grid2 - Fatal编程技术网

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

如何在C#中为Selenium Grid 2的Chrome添加配置文件首选项?,c#,google-chrome,selenium,selenium-grid2,C#,Google Chrome,Selenium,Selenium Grid2,这就是我为Chrome添加本地自动测试运行和TeamCity(CI)配置文件首选项的方式: 但当我创建新的“RemoteWebDriver”时,我必须向它发送一个中心URL和“功能”,这样我就可以向Firefox(RemoteWebDriver)发送配置文件首选项: 有人能帮我吗,我需要对Chrome做和对Firefox一样的事情。基本上我需要的是,我可以更改下载文件的默认路径。您需要执行以下操作: var chromeOptions = new ChromeOptions(); chromeO

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

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


有人能帮我吗,我需要对Chrome做和对Firefox一样的事情。基本上我需要的是,我可以更改下载文件的默认路径。

您需要执行以下操作:

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

IWebDriver driver = new RemoteWebDriver(new Uri("http://path/to/selenium/server"), chromeOptions.ToCapabilities());

您正在运行哪个版本的Selenium?Selenium.WebDriver.2.40.0和Selenium-server-standalone-2.39.0。非常感谢。很好用。嗨,你用功能(json文件)试过了吗
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;
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", DownloadPath);
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");

IWebDriver driver = new RemoteWebDriver(new Uri("http://path/to/selenium/server"), chromeOptions.ToCapabilities());