为什么 Selenium 启动 Chrome 不显示保存密码对话框?

Why Selenium started Chrome doesn't show save password dialog?

我对这个主题进行了大量搜索,但从未找到可行的解决方案。

我相信我对 Selenium 了解很多,但我不明白为什么在 Chrome 上对我不起作用,但在 Edge(基于 Chromium)上工作

使用 Selenium 启动浏览器

我用同样的方法启动了 Edge (89.0.774.54) 和 Chrome (89.0.4389.90)。

** Chrome 上的保存密码对话框 **

此保存密码对话框未出现在由我的 Selenium 代码启动的 Chrome 上。

(此屏幕截图是在我的常规 chrome 中创建的)

此外,这个密码生成器也没有出现。

Edge 上的保存密码对话框

这个保存密码对话框出现在由我的 Selenium 代码启动的 Edge 上。

我尝试解决问题的方法

我试着明确告诉 Chrome 显示这些对话框

chromeOptions.AddUserProfilePreference("credentials_enable_service", true);
chromeOptions.AddUserProfilePreference("profile.password_manager_enabled", true);

此实验基于 有人试图禁用对话框。

首选项文件

我还分析了我的 CHROME-PROFILE-PATH/Default/Preferences 文件以查看发生了什么。

原来profile.password_manager_enabledcredentials_enable_servicefalse,但加上上面几行后就变成了true.

在 Edge 上,尽管 profile.password_manager_enabled 值为 false,但对话框出现。

我还使用差异工具将 chrome 偏好与我的常规 chrome 偏好进行比较。之后我添加了这段代码但也没有用:

chromeOptions.AddUserProfilePreference("autofill.enabled", true);
chromeOptions.AddUserProfilePreference("autofill.profile_enabled", true);

我打开 chrome://flags 页面并搜索“密码”并启用所有内容。然后我重新启动 chrome 但仍然无法正常工作。

我没主意了。我错过了什么?

我也附上启动浏览器的偏好设置。请注意,我在某些与减小 json.

大小无关的地方使用了 ...

Chrome

{
   "account_id_migration_state":2,
   "account_tracker_service_last_update":"13263555192369766",
   "alternate_error_pages":{
      "backup":false
   },
   "autocomplete":{
      "retention_policy_last_version":89
   },
   "autofill":{
      "credit_card_enabled":true,
      "enabled":true,
      "profile_enabled":true
   },
   "browser":{
      "check_default_browser":false,
      "window_placement":{
         ...
      }
   },
   "countryid_at_install":18517,
   "credentials_enable_service":true,
   "data_reduction":{
      "this_week_number":2677,
      "this_week_services_downstream_foreground_kb":{
         "112189210":0,
         "35473769":39,
         "35565745":1,
         "67052219":1,
         "78917933":40
      }
   },
   "deleteDataPostSession":false,
   "distribution":{
      "import_bookmarks":false,
      "import_history":false,
      "import_search_engine":false,
      "make_chrome_default_for_user":false,
      "skip_first_run_ui":true
   },
   "dns_prefetching":{
      "enabled":false
   },
   "domain_diversity":{
      "last_reporting_timestamp":"13263555192370142"
   },
   "extensions":{
      ...
   },
   "gaia_cookie":{
      "changed_time":1619081592.874476,
      "hash":"2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
      "last_list_accounts_data":"[\"gaia.l.a.r\",[]\n]\n"
   },
   "gcm":{
      "product_category_for_subtypes":"com.chrome.windows"
   },
   "google":{
      "services":{
         "signin_scoped_device_id":"e9f1244d-0b34-4a77-882f-15bde9b4fb4a"
      }
   },
   "invalidation":{
      "per_sender_topics_to_handler":{
         "1013309121859":{
            
         },
         "8181035976":{
            
         }
      }
   },
   "media":{
      "device_id_salt":"665A83F3FBD965308E0976EAD9EC4CD6",
      "engagement":{
         "schema_version":4
      }
   },
   "media_router":{
      "receiver_id_hash_token":"cD0cqbJXrXyOARTWI2YvIQr0BfDh+mraks4pAdMG9mW1TI6WL4577DL/KpW4f/GOVPr3giW+QD1I+HmZPTYhMA=="
   },
   "ntp":{
      "custom_background_local_to_device":false,
      "num_personal_suggestions":1
   },
   "plugins":{
      "plugins_list":[
         
      ]
   },
   "previews":{
      "litepage":{
         "user-needs-notification":false
      }
   },
   "profile":{
      "avatar_index":26,
      "content_settings":{
         "enable_quiet_permission_ui_enabling_method":{
            "notifications":1
         },
         "exceptions":{
            ...
         },
         "pattern_pairs":{
            "https://*,*":{
               "media-stream":{
                  "audio":"Default",
                  "video":"Default"
               }
            }
         },
         "pref_version":1
      },
      "creation_time":"13263555191826958",
      "default_content_setting_values":{
         "geolocation":1
      },
      "default_content_settings":{
         "geolocation":1,
         "mouselock":1,
         "notifications":1,
         "popups":1,
         "ppapi-broker":1
      },
      "exit_type":"Crashed",
      "exited_cleanly":true,
      "last_engagement_time":"13263555193102304",
      "managed_user_id":"",
      "name":"Person 1",
      "password_manager_enabled":true
   },
   "safebrowsing":{
      "enabled":false,
      "metrics_last_log_time":"13263555192"
   },
   "search":{
      "suggest_enabled":false
   },
   "signin":{
      "DiceMigrationComplete":true,
      "allowed":true
   },
   "spellcheck":{
      "dictionaries":[
         "en-US"
      ],
      "dictionary":""
   },
   "token_service":{
      "dice_compatible":true
   },
   "translate":{
      "enabled":false
   },
   "translate_site_blacklist_with_time":{
      
   },
   "web_apps":{
      "did_migrate_default_chrome_apps":[
         
      ],
      "last_preinstall_synchronize_version":"89",
      "system_web_app_failure_count":0,
      "system_web_app_last_attempted_language":"en-US",
      "system_web_app_last_attempted_update":"89.0.4389.90",
      "system_web_app_last_installed_language":"en-US",
      "system_web_app_last_update":"89.0.4389.90"
   }
}

边缘

{
   "account_id_migration_state":2,
   "account_info":[
      
   ],
   "account_tracker_service_last_update":"13263555672046796",
   "alternate_error_pages":{
      "backup":false
   },
   "autocomplete":{
      "retention_policy_last_version":89
   },
   "autofill":{
      "credit_card_enabled":false,
      "enabled":false,
      "orphan_rows_removed":true,
      "profile_enabled":false
   },
   "browser":{
      "available_dark_theme_options":"All",
      "check_default_browser":false,
      "window_placement":{
         ...
      }
   },
   "browser_content_container_height":717,
   "browser_content_container_width":1036,
   "browser_content_container_x":0,
   "browser_content_container_y":80,
   "countryid_at_install":18517,
   "custom_links":{
      "list":[
         
      ]
   },
   "data_reduction":{
      "this_week_number":2677,
      "this_week_services_downstream_foreground_kb":{
         "106770712":1,
         "109536380":66,
         "12038966":0,
         "52513318":1,
         "54366456":2,
         "91564202":0
      }
   },
   "distribution":{
      "import_bookmarks":false,
      "import_history":false,
      "import_search_engine":false,
      "make_chrome_default_for_user":false,
      "skip_first_run_ui":true
   },
   "dns_prefetching":{
      "enabled":false
   },
   "domain_diversity":{
      "last_reporting_timestamp":"13263555672045746"
   },
   "download":{
      "directory_upgrade":true
   },
   "dual_engine":{
      "profile_id":"4C50PPVO",
      "shared_cookie_data":{
         
      },
      "sitelist_data_1":{
         
      },
      "sitelist_location":"",
      "sitelist_version":""
   },
   "edge":{
      "profile_sso_info":{
         "aad_sso_algo_state":1,
         "is_first_profile":true
      },
      "profile_sso_option":1,
      "services":{
         "signin_scoped_device_id":"5b695de1-5bf8-4307-845d-976fac08b6b8"
      }
   },
   "extensions":{
      "alerts":{
         "initialized":true
      },
      "chrome_url_overrides":{
         
      }
   },
   "family_safety":{
      "activity_reporting_enabled":false,
      "web_filtering_enabled":false
   },
   "media":{
      "device_id_salt":"23B14A71ACE1DFD23CFCDB82B7EFF3D7",
      "engagement":{
         "schema_version":4
      }
   },
   "media_router":{
      "receiver_id_hash_token":"he+v3KvQISCtpqAi1OSQ4yFwK1J1C8hvME9++hxTYdBgBEtTSH8FPbmRNKL1Pu/6zcx7FpLD9i0TG5frhhLomQ=="
   },
   "ntp":{
      "num_personal_suggestions":2
   },
   "plugins":{
      "plugins_list":[
         
      ]
   },
   "previews":{
      "litepage":{
         "user-needs-notification":false
      }
   },
   "profile":{
      "avatar_index":20,
      "content_settings":{
         "enable_quiet_permission_ui_enabling_method":{
            "notifications":2
         },
         "exceptions":{
            ...
         },
         "pattern_pairs":{
            "https://*,*":{
               "media-stream":{
                  "audio":"Default",
                  "video":"Default"
               }
            }
         },
         "pref_version":1
      },
      "creation_time":"13263555671479203",
      "default_content_setting_values":{
         "geolocation":1
      },
      "default_content_settings":{
         "geolocation":1,
         "mouselock":1,
         "notifications":1,
         "popups":1,
         "ppapi-broker":1
      },
      "exit_type":"Crashed",
      "exited_cleanly":true,
      "last_engagement_time":"13263555673751442",
      "managed_user_id":"",
      "name":"Profile 1",
      "observed_session_time":{
         "feedback_rating_in_product_help_observed_session_time_key_89.0.774.54":17.0
      },
      "password_hash_data_list":[
         
      ],
      "password_manager_enabled":false,
      "using_default_avatar":false,
      "using_gaia_avatar":false
   },
   "reset_prepopulated_engines":false,
   "safebrowsing":{
      "advanced_protection_last_refresh":"13263555683753670",
      "enabled":false,
      "metrics_last_log_time":"13263555671"
   },
   "search":{
      "suggest_enabled":false
   },
   "settings":{
      "a11y":{
         "caretbrowsing":{
            "enabled":false
         }
      }
   },
   "signin":{
      "allowed":true
   },
   "spellcheck":{
      "dictionaries":[
         "en-US"
      ],
      "dictionary":""
   },
   "translate":{
      "enabled":false
   },
   "translate_site_blacklist_with_time":{
      
   },
   "web_apps":{
      "did_migrate_default_chrome_apps":[
         
      ],
      "last_preinstall_synchronize_version":"89",
      "system_web_app_failure_count":0,
      "system_web_app_last_attempted_language":"en-US",
      "system_web_app_last_attempted_update":"89.0.774.54",
      "system_web_app_last_installed_language":"en-US",
      "system_web_app_last_update":"89.0.774.54"
   }
}

缺少这个

chromeOptions.AddExcludedArgument("enable-automation");