5

I am facing an issue with chrome while launching it with extensions using selenium. I have logged an issue https://code.google.com/p/chromedriver/issues/detail?id=508

For a workaround I am planing to launch chrome than enable required extension, after this connect to it using selenium.

But I am unable to so so. Can anyone help in this matter as d=webdriver.Chrome() always launches a new chrome instance. I want to connect to an already running instance of chrome.

4 Answers 4

8

**Reconnect to a driver in python selenium **
This is applicable on all drivers.
1. open a driver

    driver = webdriver.Firefox()
  1. extract to session_id and _url from driver object.

    url = driver.command_executor._url       #"http://127.0.0.1:60622/hub"
    session_id = driver.session_id            #'4e167f26-dc1d-4f51-a207-f761eaf73c31'
    

3.Use these two parameter to connect to your driver.

    driver = webdriver.Remote(command_executor=url,desired_capabilities={})
    driver.session_id = session_id
  1. And you are connected to your driver again.

    driver.get("http://www.mrsmart.in")

1
  • 1
    I'm using Chrome and this just opens up another window.
    – West
    Jan 20, 2021 at 6:47
6

This is simply not possible in Selenium, in any browser and in any programming language.

https://code.google.com/p/selenium/issues/detail?id=18

1
  • 1
    well that link mentions that it's not possible 'cos chrome would have to be started in a particular way.But if it were startd in a particular way e.g. chrome with --remote-debugging-port, then it should be technically possible
    – barlop
    Aug 12, 2022 at 21:31
3

Now it is,

  1. Fire up the java server
  2. Hit localhost:4444/wd/hub
  3. Create a session for the appropriate browser
  4. Create a remote webdriver client using the given session ID (syntax may vary depending on language bindings you are using)

reference: github issue

0

You can, it's covered here

what does "add_experimental_option("debuggerAddress", "localhost:8989")" actually do when added to Options() on Python? Selenium related

So e.g.

If you do

(adjust the command for your needs, your chrone path.. and the user profile you want to use). chrome://version can show you the chrome user profile folder for whatever chrome user.

C:\Users\User>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"  --remote-debugging-port=8989 --user-data-dir="C:\Users\User\App
Data\Local\Google\Chrome\User Data\Profile 3"

C:\Users\User>

Then in your python program

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

opt = Options()
opt.add_experimental_option("debuggerAddress", "localhost:8989")
selclient = webdriver.Chrome(options=opt)
selclient.get("http://www.dogpile.com")

That python code will not launch a new chrome window. It will connect to the already existing chrome instance that you started from eg the command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.