当前位置: 首页>>代码示例>>C#>>正文


C# ChromeOptions.AddUserProfilePreference方法代码示例

本文整理汇总了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;
        }
开发者ID:chriscore,项目名称:SpecDriver,代码行数:12,代码来源:WebDriver.cs

示例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;
 }
开发者ID:iordan93,项目名称:WallpaperDownloader,代码行数:8,代码来源:BrowserFactory.cs

示例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);
            //		}
            //	}
            //}
//.........这里部分代码省略.........
开发者ID:yalunwang,项目名称:DotnetSpider,代码行数:101,代码来源:WebDriverPool.cs

示例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;
        }
开发者ID:yalunwang,项目名称:DotnetSpider,代码行数:11,代码来源:CookieThief.cs


注:本文中的OpenQA.Selenium.Chrome.ChromeOptions.AddUserProfilePreference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。