How to change profile preference after defining driver?
profile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=profile)
After some code need to set useragent
profile.set_preference("general.useragent.override", ua)
How to set it without defining new driver?
As per the current implementation of Selenium once you configure the GeckoDriver with specific Capabilities and initialize the firefox session to open a Browsing Context, you cannot change the capabilities runtime. Even if you are able to retrieve the runtime capabilities still you won't be able to change them back.
So, in-order to change the Firefox User Preference you have to initiate a new WebDriver session.
Reference
Here is @JimEvans clear and concise comment (as of Oct 24 '13 at 13:02) related to proxy settings capability:
Outro
You can find a couple of relevant detailed discussions in: