我怎样才能添加会员的喜好在C#中的Chrome for硒格2? [英] How can I add profile preferences to Chrome for Selenium Grid 2 in C#?
本文介绍了我怎样才能添加会员的喜好在C#中的Chrome for硒格2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我怎么添加会员喜好到Chrome本地自动测试运行和TeamCity的(CI):
This is how I add profile preferences to Chrome for Local Auto-test runs and 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);
但是,当我创造新的'RemoteWebDriver',我必须把它的枢纽URL和'能力',这样,我派个人资料的喜好来火狐(以RemoteWebDriver):
But when I create new 'RemoteWebDriver', I must send it a hub URL and 'Capabilities', this way I send profile preferences to Firefox (to 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;
有人可以帮助我,我需要做的Chrome浏览器和我一样到Firefox同样的事情。基本上,我需要什么,是我可以改变下载文件的默认路径。
Can someone help me, I need to do the same thing to Chrome as I did to Firefox. Basically what I need, is that I could change the default path for downloading files.
推荐答案
您会想要做这样的事情以下内容:
You'll want to do something like the following:
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());
这篇关于我怎样才能添加会员的喜好在C#中的Chrome for硒格2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文