How to create a new (persistent) Firefox profile with Selenium in Python?

亡梦爱人 提交于 2019-12-01 17:39:22

问题


Trynig to add a new, persistent, Firefox profile with Selenium. AFAIK, when executing FirefoxProfile(), a new profile is generated using a temporary file. Ideally, this profile should be able to remain available to subsequent processes - even after the creator is closed.

Problem:

  1. Create a new Firefox profile from within Python code. This should return a FirefoxProfile object that is usable with the Firefox webdriver Selenium uses.
  2. The profile created should persist after the process ends - i.e. it should be a full-fledged profile, not just a temporary profile.

Some pointers:

  1. The profiles.ini file seems to be key. I have read some code that uses the Java class ProfilesIni to modify profile information. If this class is available for Python code, it should probably take care of most of this.

  2. If the only way to do this is to manually modify the profiles.ini file, that's acceptable. A better, more standardized solution (one that uses a library or Selenium code) would be preferable, however.

Thanks very much!


回答1:


If this helps anyone, what needs to be done is run:

firefox[.exe] -CreateProfile <profile_name>

The .exe in brackets is intended to provide for it being run under Windows.

Yes, this does not use the Selenium library in Python, but it does provide the desired result.



来源:https://stackoverflow.com/questions/16423309/how-to-create-a-new-persistent-firefox-profile-with-selenium-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!