Why chrome doesn't show save password or remember password option while running automation script?

坚强是说给别人听的谎言 提交于 2021-01-29 05:51:09

问题


While automating with selenium if a username and password is entered why doesn't chrome browser show the option to save credentials as it does in regular practice.


回答1:


As mentioned in previous answer, new instance of WebDriver opens fresh browser window, without previous cookies etc.

What could you do is:

  1. When you first start WebDriver and open login page, using selenium enter credentials, make sure you check "remember details" checkbox is present.

  2. Now once you are logged in, you can get cookies from browser using:

driver.manage().getCookies();
  1. You could get all cookies and save them in text file for example.

  2. Next time you open fresh browser, before opening page, load cookies that you previously saved.

driver.manage().getCookies().add(cookie);



回答2:


Because of the way the web-driver works, it deletes all cookies/caches of information which could accidentally fail a test, you'll notice it doesn't open an ordinary browser, its often a light-weight version of the browser.

If you want it to save cookies and caches you will A) have to specify this in your code, and B) you will have to test around the fact that you have saved passwords, so if you move your tests onto a different computer, the browsers cache will be different and your tests won't work anymore.




回答3:


Actually The Webdriver Opens The Browser Without Cookies. if You Need To Save Your cookies,you can use these commands,

 driver.manage().getCookieNamed(String arg);
   driver.manage().getCookies();
   driver.manage().getCookies().add(cookie);

All Three are use to Get The Cookie and Save The Cookie.

or

if The Browser Shows a Pop-up,to Save The User name name and Password use can use This,

var options = new ChromeOptions();
options.AddArguments("chrome.switches", "--disable-extensions --disable-extensions-file-access-check --disable-extensions-http-throttling --disable-infobars --enable-automation --start-maximized");
 options.AddUserProfilePreference("credentials_enable_service", false);
 options.AddUserProfilePreference("profile.password_manager_enabled", false);
 var driver = new ChromeDriver(options);


来源:https://stackoverflow.com/questions/53006943/why-chrome-doesnt-show-save-password-or-remember-password-option-while-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!