1

I am testing an application that requires login. Using SafariDriver when I click the "Keep Me Logged In" button every new SafariDriver instance that is created is automatically logged in as expected; but when I use FirefoxDriver or ChromeDriver I am asked for my credentials every time as if I've never logged to the site using that browser before (when I have both manually and using webdriver). Is there some setting I need to enable so FireFox and Chrome keep me logged in?

paradocslover
  • 2,932
  • 3
  • 18
  • 44
Samantha Catania
  • 5,116
  • 5
  • 39
  • 69
  • Do you have the clear cache and cookies after closing browser options checked in? – Saifur May 13 '15 at 13:58
  • @Saifur I don't think so, when I quite a restart the browsers manually I am kept logged in. Where can I check these options please? – Samantha Catania May 13 '15 at 14:01
  • See [this](https://support.mozilla.org/en-US/kb/delete-browsing-search-download-history-firefox) for firefox. Chrome [this](https://productforums.google.com/forum/#!topic/chrome/1302XTQSUWM) – Saifur May 13 '15 at 14:08
  • @Saifur Thanks, I check and both FireFox and Chrome are set to keep browser data – Samantha Catania May 13 '15 at 14:14

1 Answers1

5

This happens because WebDriver creates a new FireFox profile for every session. These profiles include caches/bookmarks/plugins etc. for more information refer to the documentation. FirefoxDirver allows you to start a FireFox with a specific profile. This can be done by using the following code:

FirefoxProfile ff = new FirefoxProfile(new File("/Path/to/profile/directory"));
driver = new FirefoxDriver(ff);

I'll update the answer if I find the way to do this in chrome

Samantha Catania
  • 5,116
  • 5
  • 39
  • 69
  • 1
    Oh yes. I misunderstood your question. I thought you do not want the browsers to save cookies. Yes this is the right way – Saifur May 13 '15 at 14:43
  • There seems to be some information on how to do it in chrome here: http://stackoverflow.com/questions/14480717/load-chrome-profile-using-selenium-webdriver I haven't had time to try it myself tough – Samantha Catania May 13 '15 at 17:21
  • for chrome, you do `options.add_argument("user-data-dir" + profile_path)` you can have the profile path be a path to an empty directory and chrome will ask you to login only once. – Ontropy Feb 08 '22 at 23:35