Repository navigation
Description
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:
- 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()) - 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
hali4ka commentedon Dec 15, 2011
Sorry I just saw that actually this is issue for python bindings of Selenium2. SO I am closing this issue.
j1z0 commentedon Dec 15, 2011
what version of the selenium python bindings are you using?
j1z0 commentedon Dec 15, 2011
ok sorry just saw that you closed this issues, please ignore my last comment
hali4ka commentedon Dec 16, 2011
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?
adwu73 commentedon Dec 27, 2011
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
j1z0 commentedon Feb 12, 2012
I've added the ability to specify your own firefox_profile_dir when you call open_browser.
Does that fix this issue for you?
mamathanag commentedon Mar 1, 2012
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.
j1z0 commentedon Mar 15, 2012
@MamathaNG are you behind a web proxy?
mamathanag commentedon Mar 15, 2012
Nope. Don't know if this helps but it worked great in chrome.
j1z0 commentedon Mar 16, 2012
Any logs? Or error msgs u can share?
mamathanag commentedon Mar 18, 2012
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!
j1z0 commentedon Mar 19, 2012
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:
mamathanag commentedon May 3, 2012
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...........
3 remaining items
j1z0 commentedon May 31, 2012
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.
mamathanag commentedon Jun 5, 2012
@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.
emanlove commentedon Dec 31, 2013
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.
rickhau commentedon Feb 24, 2015
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.
emanlove commentedon Feb 25, 2015
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!)
rickhau commentedon Feb 25, 2015
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.
emanlove commentedon Feb 25, 2015
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!
rickhau commentedon Feb 28, 2015
Hi, emanlove
Thank you very much for all the advice.
GitBartek commentedon Jul 30, 2015
Hi
Full code to set up Firefox Profil and use it in Selenium2Library.
rickhau commentedon Aug 7, 2015
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:
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.
shuvv commentedon Sep 21, 2016
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
aaltat commentedon Sep 21, 2016
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.
neetinkandhare commentedon Sep 18, 2018
Hi
i need one help, i want to import the certificate to firefox profile. can you gives code suggestion?
aaltat commentedon Sep 18, 2018
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