Run Selenium In Current Chrome Browser



Control The Current Chrome Browser With Python

Here's how to get your python scripts to control Chrome for debugging purposes without having Selenium open up a new browser itself.

Start Chrome from the terminal with this command.

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir="~/ChromeProfile"

I like Splinter as I find it easier to write.

from splinter import Browser
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option('debuggerAddress', '127.0.0.1:9222')
browser = Browser('chrome', options=chrome_options)

browser.visit('https://recycledrobot.co.uk')

Then you can go about doing your usual thing. You can read about how to control the browser in this post here: Browser Automation With Splinter - Guide The Ghost In The Machine!

Thanks for reading. x

Resources