splinter icon indicating copy to clipboard operation
splinter copied to clipboard

DeprecationWarning: firefox_profile has been deprecated, please use an Options object

Open blueyed opened this issue 4 years ago • 3 comments

Using Browser('firefox') results in a DeprecationWarning:

~/Vcs/splinter/splinter/browser.py:113: in Browser
    return get_driver(driver, retry_count=retry_count, *args, **kwargs)
~/Vcs/splinter/splinter/browser.py:84: in get_driver
    return driver(*args, **kwargs)
~/Vcs/splinter/splinter/driver/webdriver/firefox.py:32: in __init__
    firefox_profile = FirefoxProfile(profile)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.firefox.firefox_profile.FirefoxProfile object at 0x7f886862ff70>
profile_directory = None

    def __init__(self, profile_directory=None):
        """
        Initialises a new instance of a Firefox Profile

        :args:
         - profile_directory: Directory of profile that you want to use. If a
           directory is passed in it will be cloned and the cloned directory
           will be used by the driver when instantiated.
           This defaults to None and will create a new
           directory when object is created.
        """
>       warnings.warn('firefox_profile has been deprecated, please use an Options object',
                      DeprecationWarning, stacklevel=2)
E       DeprecationWarning: firefox_profile has been deprecated, please use an Options object

.venv/lib/python3.10/site-packages/selenium/webdriver/firefox/firefox_profile.py:58: DeprecationWarning: firefox_profile has been deprecated, please use an Options object

Using selenium==4.2.0,

blueyed avatar Jun 10 '22 10:06 blueyed

Not sure if it is that easy, but came up with the following - but it seems like profile_preferences should not be mapped to options maybe!?

 splinter/driver/webdriver/firefox.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git i/splinter/driver/webdriver/firefox.py w/splinter/driver/webdriver/firefox.py
index 818d8f5..751aecd 100644
--- i/splinter/driver/webdriver/firefox.py
+++ w/splinter/driver/webdriver/firefox.py
@@ -5,7 +5,6 @@
 # license that can be found in the LICENSE file.
 
 from selenium.webdriver import Firefox
-from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
 from splinter.driver.webdriver import BaseWebDriver
 from selenium.webdriver.firefox.options import Options
 
@@ -29,12 +28,15 @@ def __init__(
         **kwargs
     ):
 
-        firefox_profile = FirefoxProfile(profile)
-        firefox_profile.set_preference("extensions.logging.enabled", False)
-        firefox_profile.set_preference("network.dns.disableIPv6", False)
-
         options = options or Options()
 
+        # Defaults, can be overridden via profile_preferences.
+        options.set_preference("extensions.logging.enabled", False)
+        options.set_preference("network.dns.disableIPv6", False)
+
+        if profile:
+            options.profile = profile
+
         if capabilities:
             for key, value in capabilities.items():
                 options.set_capability(key, value)
@@ -44,7 +46,7 @@ def __init__(
 
         if profile_preferences:
             for key, value in profile_preferences.items():
-                firefox_profile.set_preference(key, value)
+                options.set_preference(key, value)
 
         if headless:
             options.add_argument("--headless")
@@ -53,7 +55,6 @@ def __init__(
             options.add_argument("-private")
 
         driver = Firefox(
-            firefox_profile,
             options=options,
             **kwargs,
         )

Also it might be wanted to keep the feature of having persistent profiles after all, at least in/via Splinter?!

blueyed avatar Jun 13 '22 18:06 blueyed

There's https://github.com/cobrateam/splinter/pull/982 already.

blueyed avatar Jun 16 '22 20:06 blueyed

Fixed by #982

javascript-error avatar Jun 21 '22 03:06 javascript-error