How to connect Selenium to an existing browser instance, Firefox edition. See the example Python script.
(Disclaimer: The browser has to be reopened using the -marionette flag.)
This could be helpful for, for example, logging in to a web application yourself before running your script, so that your script doesn't have to deal with logging in (also helps with avoiding repeated logins and being subject to associated security measures).
- A Firefox browser
- geckodriver (https://github.com/mozilla/geckodriver/releases). Make sure the geckodriver executable is in your PATH.
- Create a new Firefox instance with the
-marionetteflag,1 for example on Windows:
C:\Program` Files\Mozilla` Firefox\firefox.exe -marionette- Selenium uses geckodriver to connect to Marionette; in your script, pass the options
--connect-existing --marionette-port 2828to geckodriver. (2828 is the default port for Marionette, you can change this in Firefox configs by typing in about:config in your browser, searching for themarionette.portpreference and then changing the default value.) - Your script is now primed to access the browser instance created in step 1. Write the rest of your script.
- Run the script—if you have set the preference
marionette.debugging.clicktostartto true, the browser will prompt Click to start execution of marionette tests.
Footnotes