public ChromeDriverBuilder SetDownloadPath(string downloadFilepath)
        {
            Options.AddUserProfilePreference("download.default_directory", downloadFilepath);
            Options.AddUserProfilePreference("download.prompt_for_download", false);
            //Options.AddUserProfilePreference("intl.accept_languages", "nl");

            DisablePopupBlocking();

            return(this);
        }
Example #2
0
        /// <summary>
        /// Adds the User Profile Preferences from the app.config file
        /// </summary>
        private void AddUserProfilePreferences()
        {
            object objValue = new object();
            string name     = "";

            try
            {
                var preferenceList = Chrome.UserProfilePreferences;

                if (preferenceList != null && preferenceList.Contains(","))
                {
                    var list = preferenceList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string preference in list)
                    {
                        string[] setting = preference.Split(new string[] { "=", "|" }, StringSplitOptions.RemoveEmptyEntries);
                        name = setting[0];
                        Type valueType = Type.GetType(setting[2]);
                        objValue = Convert.ChangeType(setting[1], valueType);
                        Options.AddUserProfilePreference(name, objValue);
                    }
                }
            }
            catch (Exception ex)
            {
                switch (BaseSettings.DebugLevel)
                {
                case EnumConsoleDebugLevel.Human:
                    Console.Out.WriteLine("Unable to add the user profile settings specified in the config file");
                    Console.Out.WriteLine("Setting: {0} | Value: {1}", name, objValue.ToString());
                    break;

                case EnumConsoleDebugLevel.NotSpecified:
                case EnumConsoleDebugLevel.Message:
                    Console.Out.WriteLine(ex.Message);
                    break;

                case EnumConsoleDebugLevel.StackTrace:
                    Console.Out.WriteLine(ex.Message);
                    Console.Out.WriteLine(ex.StackTrace);
                    break;
                }
            }
        }
        public ChromeDriverBuilder DisablePopupBlocking()
        {
            Options.AddUserProfilePreference("disable-popup-blocking", "true");

            return(this);
        }