Пример #1
0
        /// <summary>
        /// The create chrome browser instance.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     InvalidOperationException exception.
        /// </exception>
        /// <returns>
        /// The <see cref="BrowserAbstract"/>.
        /// </returns>
        private static BrowserAbstract CreateChromeBrowserInstance()
        {
            var options = new ChromeOptions();

            options.AddArgument("--disable-xss-auditor");
            options.AddArgument("--no-experiments");
            options.AddArgument("--disable-translate");
            options.AddArgument("--disable-plugins");
            options.AddArgument("--disable-extensions");
            options.AddArgument("--no-default-browser-check");
            options.AddArgument("--clear-token-service");
            options.AddArgument("--disable-default-apps");
            options.AddArgument("--enable-logging");
            options.AddArgument("--disable-web-security");
            options.AddArgument("--allow-file-access-from-files");
            options.AddArgument("--enable-file-cookies");

            var driver = new ChromeDriver(options);

            var capabilities =
                driver.CastTo <RemoteWebDriver>().Capabilities.GetCapability("chrome") as IDictionary <string, object>;

            if (capabilities == null)
            {
                throw new InvalidOperationException("Unable to get capabilities for Chrome.");
            }

            var browser = new ChromeBrowser(driver, capabilities["userDataDir"] as string);

            return(browser);
        }