简体   繁体   中英

How to Force Selenium to use Permanent Firefox Profiles with WebDriver?

I'm using Selenium Web Driver API with Java. Whenever I run Web Driver, it automatically creates a tmp Firefox Profile and executes all driver related code relative to the tmp profile.

My issue is not with the extra space this creates as asked in this question: How to stop Selenium from creating temporary Firefox Profiles using Web Driver? and I know I could call driver.quit to clear the resources used by the tmp profile.

Rather, my issue is I want to use the permanent Firefox Profile so that the next time I launch this FF profile I inherit all the cookies and cache of the previous profile. I know I can manually save and add cookies each time but this is tedious.

So, is there any way to force Firefox not to create a tmp profile and launch Firefox as if I was browsing normally using the permanent profile? I just want it to launch as if I was browsing like a normal user.

Thanks

Generally Selenium do not support cross-session cookies.

Most easy way is to use Serialization. You need to create wrapper class around selenium's cookie and make it serializable. And create class CookiesManager where will be 2 methods: SaveSession() -- to save and RestoreSession() - to restore from serialized file.

Another way is to save some cookies information into some temp cookies file. Like.... Csv or XML. Sample of this way you can see here: Keep user logged in - save cookies using web driver but only for c#.


Using specific profile:

ProfilesIni profile = new ProfilesIni();

FirefoxProfile myprofile = profile.getProfile("profileToolsQA");

WebDriver driver = new FirefoxDriver(myprofile);

to create some additional profile for firefox you need to run firefox profile manager by the following way: firefox.exe -p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM