Skip to content

Issue with Firefox Profiles #18

Closed
Closed

Description

@hali4ka

Hi,

after updating to Firefox 8 I had the problem that my tests were not executed. The browser windows is getting opened but after that nothing happens. After I long search I find out that selenium2Lib uses default Firefox Profile which is in the installation path of the library. For some reason this can not be loaded.

I have fixed this for me locally in this way:

  1. in file _browsermanagement.py - line 332 I removed the FIREFOX_PROFILE_DIR so that this line looks like this now:
    browser = webdriver.Firefox(webdriver.FirefoxProfile())
  2. changes in firefox_profile.py - method

def init(self,profile_directory=None):

Here are two changes possible depending of this what you want to do:

2.1 if you want to use your own specified profile the method will looks like this:
self.default_preferences = copy.deepcopy(FirefoxProfile.DEFAULT_PREFERENCES)
self.profile_dir = '<PATH_TO_YOUR_FF_PROFILE>'

    self._read_existing_userjs()
    self.extensionsDir = os.path.join(self.profile_dir, "extensions")
    self.userPrefs = os.path.join(self.profile_dir, "user.js")

2.2 If you want that every time anonymous profile is created in the temp folder and used that it will look like this:

    self.default_preferences = copy.deepcopy(FirefoxProfile.DEFAULT_PREFERENCES)
    self.profile_dir = profile_directory
    if self.profile_dir is None:
        self.profile_dir = self._create_tempfolder()
    else:
        newprof = os.path.join(tempfile.mkdtemp(),
            "webdriver-py-profilecopy")
        shutil.copytree(self.profile_dir, newprof)
        self.profile_dir = newprof
    self._read_existing_userjs()
    self.extensionsDir = os.path.join(self.profile_dir, "extensions")
    self.userPrefs = os.path.join(self.profile_dir, "user.js")

Will it be possible to fix this in future releases, so that no code changes are needed after update?

Thanks

Activity

  1. hali4ka commented on Dec 15, 2011

    @hali4ka
    Author

    Sorry I just saw that actually this is issue for python bindings of Selenium2. SO I am closing this issue.

  2. j1z0 commented on Dec 15, 2011

    @j1z0
    Contributor

    what version of the selenium python bindings are you using?

  3. j1z0 commented on Dec 15, 2011

    @j1z0
    Contributor

    ok sorry just saw that you closed this issues, please ignore my last comment

  4. hali4ka commented on Dec 16, 2011

    @hali4ka
    Author

    I am opening this issue again as the problem was not only in the python bindings.

    Here is a patch for Selenium2Library. In the file _browsermanagement.py following needs to be changed:
    from
    if browser_token == '*firefox':
    browser = webdriver.Firefox(webdriver.FirefoxProfile(FIREFOX_PROFILE_DIR))

    make
    if browser_token == '*firefox':
    browser = webdriver.Firefox(webdriver.FirefoxProfile())

    Can you please change it for future releases?

  5. adwu73 commented on Dec 27, 2011

    @adwu73
    Contributor

    I noticed the same issue on FF4 / Windows 2003 Server, don't know why, however if I change init to init, I will get python runtime error, saying that default_perferences is not defined

  6. j1z0 commented on Feb 12, 2012

    @j1z0
    Contributor

    I've added the ability to specify your own firefox_profile_dir when you call open_browser.

    Does that fix this issue for you?

  7. mamathanag commented on Mar 1, 2012

    @mamathanag

    Guys I am still facing this issue where open browser in Selenium2Library opens the browser but does nothing. I tried the solution recommended above by editing file _browsermanagement.py but no luck..
    Any help is appreciated.

  8. j1z0 commented on Mar 15, 2012

    @j1z0
    Contributor

    @MamathaNG are you behind a web proxy?

  9. mamathanag commented on Mar 15, 2012

    @mamathanag

    Nope. Don't know if this helps but it worked great in chrome.

  10. j1z0 commented on Mar 16, 2012

    @j1z0
    Contributor

    Any logs? Or error msgs u can share?

  11. mamathanag commented on Mar 18, 2012

    @mamathanag

    Hey Jeremy,
    I did troubleshoot a little bit and found that the webdriver extension that gets plugged into firefox runtime is disabled.
    So during the execution I go into the instance of the browser controlled by the script and enable the extension webdriver.xpi.. things work!
    I search around and found a way to play with the firefox settings, but no luck. Any idea how I could get the webdriver plugin/extension to be enabled without manual intervention?
    I really appreciate your help!

  12. j1z0 commented on Mar 19, 2012

    @j1z0
    Contributor

    Strange. It should be enabled. I would try reinstalling Firefox / selenium and see if that helps. Otherwise u can check out this page and try to programmatically set the preferences for webdriver

    http://code.google.com/p/selenium/wiki/FirefoxDriver

    Cheers,
    Jeremy

    On Mar 19, 2012, at 1:26, mamathanagreply@reply.github.com wrote:

    Hey Jeremy,
    I did troubleshoot a little bit and found that the webdriver extension that gets plugged into firefox runtime is disabled.
    So during the execution I go into the instance of the browser controlled by the script and enable the extension webdriver.xpi.. things work!
    I search around and found a way to play with the firefox settings, but no luck. Any idea how I could get the webdriver plugin/extension to be enabled without manual intervention?
    I really appreciate your help!


    Reply to this email directly or view it on GitHub:
    #18 (comment)

  13. mamathanag commented on May 3, 2012

    @mamathanag

    Alright, I found a fix for this issue and thought will document the same .. maybe it will help someone someday...

    First off, Firefox 11 and above is not compatible with Webdriver, so there is really no option to even enable the webdriver like I used to on Firefox 10.
    On Firefox Version 10 you will see a blank window of firefox and nothing happens further.... If you check Firefox->Addons->extensions, you will notice that Webdriver Addon is disabled and during the run if you manually enable it , the run will go thru smooth. To automatically enable the webdriver(without manual intervention), do the following :

    In the default firefox profile available in Selenium2Library : "C:\Python27\Lib\site-packages\Selenium2Library\resources\firefoxprofile". Click on "prefs" file, right click , select edit.

    Add the following two lines at the end of the file.

    user_pref("extensions.alwaysUnpack", true);
    user_pref("extensions.autoDisableScopes", 0);

    ---Save and run your test script... Hola!....works instantaneously...........

  14. 3 remaining items

  15. j1z0 commented on May 31, 2012

    @j1z0
    Contributor

    For me and the team I am working with we have no issues with eithe FF 11 or the default profile in S2L. I'm not against a change to the profile I just can't reproduce the existing issue that @mamathanag Is experiencing so I wouldn't be able to test if the change was correct. Thus @mamathanag would u mind submitting the patch? I could then at least verify thr everything still works from my end with ur new patch and if it does I'll merge it.

  16. mamathanag commented on Jun 5, 2012

    @mamathanag

    @j1z0,@emanlove, I just saw your comments today, hence the delay. The Fix for the profile is on firefox 10/selenium2Library combination. I have no problem submitting a patch for this but is that really what we want to do? I am thinking, we need to get the latest firefox version working. I have not tried Firefox 11 lately, let me do that and will update you all with my findings.

  17. emanlove commented on Dec 31, 2013

    @emanlove
    Member

    Closing due to length of time since issue was last updated.

    Note: Recent addition of the 'Create WebDriver' keyword [#245] might resolve this issue or provide sufficient workaround.

  18. rickhau commented on Feb 24, 2015

    @rickhau

    I also have a similar issue to deal with autosave using the selenium2library. However, I do not want to copy the entire profile directory as selenium2library only eats the profile directory. What I want is as following to set the preference for specific settings in the preference then pass that to the webdriver. Would like to know if selenium2library offers this capability to pass the firefox_profile(fp) to webdriver instead of directory as user might want to set some settings while running the code?

    Code snippets:
    fp = webdriver.FirefoxProfile()
    fp.set_preference("browser.download.folderList",2) fp.set_preference("browser.download.manager.showWhenStarting",False) fp.set_preference("browser.download.dir",getcwd()) fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
    browser = webdriver.Firefox(firefox_profile=fp)

    Selenium2Library:
    open_browser(self, url, browser='firefox', alias=None,remote_url=False, desired_capabilities=None,ff_profile_dir=None)

    Any advice is highly appreciated.

  19. emanlove commented on Feb 25, 2015

    @emanlove
    Member

    We added a while back an alternative to 'Open Browser' keyword, that is 'Create Webdriver' though I am not sure you can accomplish exactly the above code. Might give that a try. What do you mean by "eats the profile directory". If you provide the directory/profile it shouldn't eat this one up; only the temporary one if you don't provide one. Actually if I remember correctly it copies the one you provide into a temporary directory which does get consumed. But I don't see how this could be a probem ounless you make a change in the profile in the test close the session and then reopen another hoping to save some information.

    Note also you don't have to provide all the files there is in either the one that is seen within the Firefox profile directory. I had narrowed it down to, a while ago so this may have changed since then, but just the permissions.sqlite and pref.js files. Of course the change you write about you need to change are within the prefs.js file. I have an system under test which requires a java applet to run and thus to automate and forgo the java security questions I have to create my own firefox profile. (I also use the 'Create WebDriver' keyword for a Chrome solution and IE has such poor security I do it once manually and then I am all set!)

  20. rickhau commented on Feb 25, 2015

    @rickhau

    Hi, emanlove

    Many thanks for your advice and more information. What I meant by 'eats the profile directory' is the ff_profile_dir only accepts a directory where the profile(permission.sqlite and pref.js) resides. What I am looking for is to set the preference by using webdriver.FirefoxProfile() then pass that preference instance to open_browser(). Then, I can have my browser open with some preference set already instead of copying preference file around. However, It seems that I only can use this way for now to pass prefs.js to browser before testing. The reason behind is: I have more than 3 servers as my test environment to checkout my test code from my git server then kick off the test, so I prefer to finish all tasks in the test code instead of copying some files around in the test environment if possible. Btw, thanks for providing the information about two files related to the Firefox profile. That is good to know.

    Thanks.

  21. emanlove commented on Feb 25, 2015

    @emanlove
    Member

    You could just check in these two files and just make them part of the build process; either the build process which creates the test machine or the build process which checks out the code and runs the tests.

    There are some issues submitted to the selenium project and discussions online requesting from the selenium team to allow people to keep the profile around. The selenium developers have, I think rightfully so, given good arguments as to why this is a bad idea. I don't have any links but you can do some google searches. So the above solution is general what is used and you should be able to easily add a profile to your build process making it a clean setup and test environment. Good luck!

  22. rickhau commented on Feb 28, 2015

    @rickhau

    Hi, emanlove
    Thank you very much for all the advice.

  23. GitBartek commented on Jul 30, 2015

    @GitBartek

    Hi
    Full code to set up Firefox Profil and use it in Selenium2Library.

    from Selenium2Library import Selenium2Library
    from selenium.webdriver import FirefoxProfile
    
    fprofile= FirefoxProfile()
    fprofile.set_preference("browser.download.dir", "D:\\WebDriverdownloads");
    fprofile.set_preference("browser.download.folderList", 2);
    fprofile.set_preference("browser.helperApps.neverAsk.saveToDisk","application/pdf;" );
    fprofile.set_preference( "browser.download.manager.showWhenStarting", False );
    fprofile.set_preference( "pdfjs.disabled", True );
    
    sel=Selenium2Library()
    sel.create_webdriver('Firefox',firefox_profile=fprofile)
    
  24. rickhau commented on Aug 7, 2015

    @rickhau

    Hi,
    I was looking for a way to pass the firefoxprofile to open_browser()
    Today, I found the solution for myself.
    So, I'd like to share with anyone who might struggle in the same problem.

    Here comes the code snippet:

           from Selenium2Library import Selenium2Library
           from selenium.webdriver import FirefoxProfile
            fp = FirefoxProfile()
            fp.set_preference("browser.download.folderList", 2)
            fp.set_preference("browser.download.manager.showWhenStarting", False)
            fp.set_preference("browser.download.dir", os.getcwd())
            fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plan")
            fp.update_preferences()
            sel  = Selenium2Library.Selenium2Library()
            sel.open_browser(url='http://10.0.0.2', ff_profile_dir=fp.path)

    This can offer a way to support FirefoxProfile() instance and use fp.path to use open_browser for your convenience.

    Hope this helps anyone who might need.

  25. shuvv commented on Sep 21, 2016

    @shuvv

    hii my browser is opening but specified link is not opening what should i do
    browser is ff
    20160921 16:20:02.925 : INFO : Opening browser 'ff' to base url 'http://demo.mahara.org/'
    20160921 16:21:35.428 : FAIL : No browser is open
    20160921 16:21:35.433 : WARN : Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
    20160921 16:21:35.483 : FAIL :
    WebDriverException: Message: Can't load the profile. Profile Dir: c:\users\sharad\appdata\local\temp\tmpmluyxv\webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.

    Ending test: Login Suite.Valid user login

  26. aaltat commented on Sep 21, 2016

    @aaltat
    Contributor

    Have you updated your selenium to the latest version? If you haven't, please update and try again.

    If selenium update doesn't not resolve the problem, using a Firefox version, which is actually supported by the selenium is required. Last time I did upgrade my Firefox to version 47.0.1 or 47.0.2. Can't not anymore remember exactly.

  27. neetinkandhare commented on Sep 18, 2018

    @neetinkandhare

    Hi
    i need one help, i want to import the certificate to firefox profile. can you gives code suggestion?

  28. aaltat commented on Sep 18, 2018

    @aaltat
    Contributor

    It's really rude to hijack other issues with your own agenda. Specially when it's not related.

    For more support, please see proper channels from here: https://github.com/robotframework/SeleniumLibrary/blob/master/README.rst#support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions