Run Selenium In Current Chrome Browser

in #python5 days ago

cover.png

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.

Thanks for reading. x

Resources

Coin Marketplace

STEEM 0.15
TRX 0.23
JST 0.031
BTC 81466.13
ETH 2149.10
USDT 1.00
SBD 0.64