问题
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:
When you first start WebDriver and open login page, using selenium enter credentials, make sure you check "remember details" checkbox is present.
Now once you are logged in, you can get cookies from browser using:
driver.manage().getCookies();
You could get all cookies and save them in text file for example.
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