Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium use of Firefox profile

I try to use Selenium Webdriver and Python on Windows 10 system to make some automation of browser actions. But I have this problem: Selenium-started Firefox window doesn't "see" that I am already logged in and target site sends me to login page. So I assumed that Selenium not really uses the profile, but just a copy of it.

I would like to know:

  1. Is my conclusion about actual use of copy of profile true?
  2. If 1. is true, is there a way to use really everything from existing profile?
  3. If my conclusion is not true, please prove it and point me to the direction where I can find out what information can be used for session, why Selenium could fail to send it and how to force it to do so actually.

Edit:

from selenium import webdriver
fp = webdriver.FirefoxProfile('C:/Users/<user name>/AppData/Roaming/Mozilla/Firefox/Profiles/abc3defghij2.ProfileName')
driver = webdriver.Firefox(fp)
driver.get("https://www.example.com/membersarea")
like image 673
svgrafov Avatar asked May 16 '16 05:05

svgrafov


People also ask

What is the use of Firefox profile in Selenium WebDriver?

Firefox profiles include custom preferences that you would like to simulate an environment for your test script. For example, you might want to create a profile that sets preferences to handle the download popup programmatically during your test run.

What is Firefox profile and what is the use of it?

Firefox saves your personal information such as bookmarks, passwords and user preferences in a set of files called your profile, which is stored in a separate location from the Firefox program files. You can have multiple Firefox profiles, each containing a separate set of user information.

How do I use Firefox options in Selenium?

FirefoxOptions options = new FirefoxOptions(); driver = new RemoteWebDriver(new URL("http://10.x.x.x:4444/wd/hub"), options); When you start your Selenium Nodes, it displays a log information on using new FirefoxOptions preferred to 'DesiredCapabilities. firefox() along with all other browser options.

Do you need Firefox for Selenium?

Selenium IDE by Selenium Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests.


1 Answers

Selenium indeed uses a copy of the profile, though that ought not to cause any problems. I think your issue has more to do with session cookies vs. persistent cookies.

On support.mozilla.org is a list indicating what information is actually stored in your profile. Note that cookies are among these, however session-cookies are not stored in cookies.sqlite which is the reason Selenium cannot rebuild your session since it does not appear in the profile.

Many sites, however, offer a remember-me or a stay-logged-in option on their login page which, if used, will store a persistent cookie by which the session can be restored. I used the following script to test this out with gmail,

from selenium import webdriver

url = "https://mail.google.com"
fp = webdriver.FirefoxProfile('/Users/<username>/Library/Application Support/Firefox/Profiles/71v1uczn.default')

driver = webdriver.Firefox(fp)
driver.get(url)

When I run this script after having logged into gmail with the stay-logged-in option enabled, then Selenium is able to access my inbox. If the stay-logged-in option is not enabled the session is destroyed upon closing my browser and thus Selenium cannot restore it either.

The screenshot below shows that session cookies are indeed not stored in cookies.sqlite and thus do not appear in the profile when used by Selenium.

Firefox cookies in cookies.sqlite and firebug

like image 172
sowa Avatar answered Oct 04 '22 02:10

sowa