Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to an already running instance of chrome using selenium in python

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.

like image 543
Nitin_k29 Avatar asked Sep 10 '13 14:09

Nitin_k29


1 Answers

**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")

like image 51
Manoj Sahu Avatar answered Sep 22 '22 06:09

Manoj Sahu