AddExtension() public méthode

Adds a path to a packed Chrome extension (.crx file) to the list of extensions to be installed in the instance of Chrome.
public AddExtension ( string pathToExtension ) : void
pathToExtension string The full path to the extension to add.
Résultat void
 private static ChromeOptions GetChromeOptions()
 {
     var option = new ChromeOptions();
     option.AddArgument("start-maximized");
     option.AddExtension(@"C:\downloads\GoogleAnalytics.crx");
     option.Proxy = null;
     return option;
 }
        public NaverCrawler()
        {
            string id = ConfigurationManager.AppSettings["id"];
            string password = ConfigurationManager.AppSettings["password"];
            var processList = Process.GetProcessesByName("chromedriver");
            foreach( var process in processList )
            {
                process.Kill();
            }

            var chromeDriverService = ChromeDriverService.CreateDefaultService();
            chromeDriverService.HideCommandPromptWindow = true;

            var option = new ChromeOptions();
            option.AddExtension("3.7_0.crx");
            driver = new ChromeDriver(chromeDriverService, option );

            while (driver.WindowHandles.Count < 2)
            {
                Thread.Sleep(100);
            }

            driver.SwitchTo().Window(driver.WindowHandles[1]);

            WebDriverWait _wait = new WebDriverWait(driver, new TimeSpan(0, 1, 0));

            driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 10));

            _wait.Until(d => d.FindElement(By.Id("user_email")));
            driver.FindElementById("user_email").SendKeys(String.Format("{0}@naver.com\n", id));
            _wait.Until(d => d.FindElement(By.Id("user_password")));
            driver.FindElementById("user_password").SendKeys(password);
            driver.FindElementById("loginbtn").Click();

            driver.SwitchTo().Window(driver.WindowHandles[0]);
            driver.Url = loginFormUrl;
            driver.FindElementByCssSelector("#id").SendKeys(id);
            driver.FindElementByCssSelector("#pw").SendKeys(password);

            driver.FindElementByCssSelector("input.int_jogin").Click();

            cookieContainer = new CookieContainer();
            ReadOnlyCollection<OpenQA.Selenium.Cookie> cookieCollections = null;

            bool sessionFound = false;
            while (!sessionFound)
            {
                cookieCollections = driver.Manage().Cookies.AllCookies;
                foreach( var cookie in cookieCollections )
                {
                    if ( cookie.Name == "JSESSIONID" )
                    {
                        sessionFound = true;
                        break;
                    }
                }
            }
            foreach( var cookie in cookieCollections )
            {
                cookieContainer.Add(new System.Net.Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain));
            }

            driver.Quit();
        }
Exemple #3
-14
        protected void Start()
        {
            LoadConfiguration();

            ChromeOptions options = new ChromeOptions();
            options.AddExtension(ExtensionLocation);

            if (_isLocal)
            {
               WebDriver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(120));
               WebDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
            }
            else
            {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.SetCapability(ChromeOptions.Capability, options);
                WebDriver = new RemoteWebDriver(new Uri(""), DesiredCapabilities.Chrome(), TimeSpan.FromSeconds(120));
                WebDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
            }

            NgWebDriver = new NgWebDriver(WebDriver);
        }