How to create instance of driver attached to manually opened browser?

512 views
Skip to first unread message

bill nom nom

unread,
Dec 14, 2019, 9:04:01 AM12/14/19
to Selenium Users
How to create instance of driver attached to manually opened browser?

I'm using C#, VS2017, Windows 10 Home Edition.

NuGet packages::
<package id="Selenium.Support" version="3.141.0" targetFramework="net461" />
  <package id="Selenium.WebDriver" version="3.141.0" targetFramework="net461" />
  <package id="Selenium.WebDriver.ChromeDriver" version="79.0.3945.3600" targetFramework="net461" />

Alex K

unread,
Dec 17, 2019, 8:55:16 AM12/17/19
to Selenium Users
I do not think it is possible since for the communication you need a seesionId which is created when you start your webdriver.

Tricia Crichton

unread,
Dec 17, 2019, 12:20:54 PM12/17/19
to Selenium Users
Yes, this is possible with Chrome.
You must start Chrome with the added switch:
--remote-debugging-port=<port>
You can pick any port number that will be free.

Then, in ChromeDriver, you need to add an option:
var options = new ChromeOptions();
options.DebuggerAddress="<host>:<port>";
Use the host where you started Chrome (usually localhost), and the same port.

If you start Chrome with the default profile, and you already have a Chrome instance running on that profile, this won't work, and a new Chrome instance won't actually start - it will just open a new window.

In that case, you can add a new user-data-dir, and it will start a new Chrome instance.
--user-data-dir=<dir>

Mallichetty Hemanth Kumar

unread,
Dec 17, 2019, 12:26:45 PM12/17/19
to seleniu...@googlegroups.com
I'm using selenium with Java, I have done it for my project. Try the same in c#

Attached the pictures to follow the steps to access already opened browser

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/12efd572-9f1d-48a8-aa77-f399e939c284%40googlegroups.com.
IMG_20191127_130010.jpg
IMG_20191127_130020.jpg

bjm 34980

unread,
Dec 22, 2019, 9:56:50 AM12/22/19
to Selenium Users
Hello
I am very interested by this question.
However I don't understand well hos to proceed.
It seems to me we should have a way to enumerate all the opened Chrome browsers (e.g. different Chromes on different desktops).
Then for each browser we should enumerate all the open tabs
Once we find the tab we are looking for we take control of browser in this tab and send the commands we want to send.
It is not clear to me how these actions can be performed
Can somebody give me a hint on how to proceed ?
in particular I did not understand the user-data-dir piece.
Thanks in advance

Tricia Crichton

unread,
Dec 23, 2019, 1:59:40 PM12/23/19
to Selenium Users
user-data-dir is just a directory on the computer where Chrome will store the user profile. By default, ChromeDriver always starts Chrome with a new one, but code can specify anything  - including an already existing value. This is just passed to the Chrome command line.

Chrome will never run 2 instances in the same user data dir. If a Chrome instance is already running and you run chrome.exe again with the same user data dir (ie, the default), the system will actually create a new window for the same instance. If that previous instance was not run with the remote-debugging-port, then adding that switch to the second call to chrome.exe will NOT add the switch to the existing instance.

By giving chrome.exe a new user-data-dir, you will force it to truly start a new instance, and the debugging switch will be set as requested. 

Alternatively, close all open chrome windows, confirm that all chrome processes have stopped, then run chrome with the remote-debugging port.
Reply all
Reply to author
Forward
0 new messages