本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeOptions.AddUserProfilePreference方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeOptions.AddUserProfilePreference方法的具体用法?C# ChromeOptions.AddUserProfilePreference怎么用?C# ChromeOptions.AddUserProfilePreference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeOptions
的用法示例。
在下文中一共展示了ChromeOptions.AddUserProfilePreference方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateChromeDriverAutoDownload
public static IWebDriver CreateChromeDriverAutoDownload(string downloadDirectory)
{
ChromeOptions opts = new ChromeOptions();
opts.AddUserProfilePreference("download.default_directory", downloadDirectory);
opts.AddUserProfilePreference("download.prompt_for_download", "false");
var ChromeDriver = new ChromeDriver(opts);
ChromeDriver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
ChromeDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
ChromeDriver.Manage().Window.Maximize();
return ChromeDriver;
}
示例2: GetChromeBrowser
private static IWebDriver GetChromeBrowser()
{
var service = ChromeDriverService.CreateDefaultService(Path.GetFullPath(Constants.DriversDirectory));
var options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", Path.GetFullPath(Constants.WallpapersDirectory));
var browser = new ChromeDriver(service, options);
return browser;
}
示例3: Get
public WebDriverItem Get()
{
CheckRunning();
if (_webDriverList.Count < _capacity)
{
if (_innerQueue.Count == 0)
{
IWebDriver e = null;
switch (_browser)
{
case Browser.Phantomjs:
var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();
if (!string.IsNullOrEmpty(_option.Proxy))
{
phantomJsDriverService.Proxy = _option.Proxy;
phantomJsDriverService.ProxyAuthentication = _option.ProxyAuthentication;
}
e = new PhantomJSDriver(phantomJsDriverService);
break;
case Browser.Firefox:
string path = Environment.ExpandEnvironmentVariables("%APPDATA%") + @"\Mozilla\Firefox\Profiles\";
string[] pathsToProfiles = Directory.GetDirectories(path, "*.webdriver", SearchOption.TopDirectoryOnly);
FirefoxProfile profile;
if (pathsToProfiles.Length == 1)
{
profile = new FirefoxProfile(pathsToProfiles[0], false);
}
else
{
profile = new FirefoxProfile();
}
if (!_option.AlwaysLoadNoFocusLibrary)
{
profile.AlwaysLoadNoFocusLibrary = true;
}
if (!_option.LoadImage)
{
profile.SetPreference("permissions.default.image", 2);
}
if (!_option.LoadFlashPlayer)
{
profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
}
if (!string.IsNullOrEmpty(_option.Proxy))
{
string[] p = _option.Proxy.Split(':');
string host = p[0];
int port = Convert.ToInt32(p[1]);
profile.SetPreference("network.proxy.ftp_port", port);
profile.SetPreference("network.proxy.gopher", host);
profile.SetPreference("network.proxy.gopher_port", port);
profile.SetPreference("network.proxy.http", host);
profile.SetPreference("network.proxy.http_port", port);
profile.SetPreference("network.proxy.no_proxies_on", "localhost,127.0.0.1,<-loopback>");
profile.SetPreference("network.proxy.share_proxy_settings", true);
profile.SetPreference("network.proxy.socks", host);
profile.SetPreference("network.proxy.socks_port", port);
profile.SetPreference("network.proxy.ssl", host);
profile.SetPreference("network.proxy.ssl_port", port);
profile.SetPreference("network.proxy.type", 1);
}
e = new FirefoxDriver(profile);
break;
case Browser.Chrome:
ChromeDriverService cds = ChromeDriverService.CreateDefaultService();
cds.HideCommandPromptWindow = true;
ChromeOptions opt = new ChromeOptions();
if (!_option.LoadImage)
{
opt.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
}
if (!string.IsNullOrEmpty(_option.Proxy))
{
opt.Proxy = new Proxy() { HttpProxy = _option.Proxy };
}
e = new ChromeDriver(cds, opt);
break;
}
_innerQueue.Enqueue(new WebDriverItem(e));
_webDriverList.Add(new WebDriverItem(e));
}
}
//else
//{
// while (true)
// {
// lock (_innerQueue)
// {
// if (_innerQueue.Count > 0)
// {
// break;
// }
// Thread.Sleep(150);
// }
// }
//}
//.........这里部分代码省略.........
示例4: GetWebDriver
protected RemoteWebDriver GetWebDriver()
{
ChromeDriverService cds = ChromeDriverService.CreateDefaultService();
cds.HideCommandPromptWindow = true;
ChromeOptions opt = new ChromeOptions();
opt.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
RemoteWebDriver webDriver = new ChromeDriver(cds, opt);
webDriver.Manage().Window.Maximize();
return webDriver;
}