1

Trying to run tests on an existing Chrome browser using Selenium in C#. I'm doing this on my macbook.

Problem is that the c# code doesn't connect with the browser with the specified port. Instead the code keeps opening it's own browser. It shouldn't matter how many instances of chrome are running. It should only connect to the one with the port open, instead it timesout and appears to be looking for a different port than the one I specified.

Steps:

I manually open the chrome browser with a debugging port using the terminal:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  --remote-debugging-port=9014

Then the C# code to attach to the browser and run a simple Selenium script:

var chromeDriverLocation = "/Users/jb/Projects/fjsdlfsdf/fjsdlfsdf/bin/Debug"; 
var options = new ChromeOptions();
options.DebuggerAddress = "localhost:9014";  // specifying the port of the existing browser
Driver = new ChromeDriver(chromeDriverLocation, options);
Driver.Navigate().GoToUrl("https://google.com");

But I get this error which refers to a completely different port:

OpenQA.Selenium.WebDriverException
The HTTP request to the remote WebDriver server for URL http://localhost:53678/session timed out after 60 seconds.
fractal
  • 1,649
  • 17
  • 31

1 Answers1

-1

Try closing all chrome browser instance first

In chrome even if you give the flag --debugger-address it might not start chrome with that debugger port if any process still keeps that port open. It also won't throw any error.

So validate chrome indeed opened in that port by opening http://localhost:9014 in any browser or tab

if it doesn't open it means chrome was not started with that debug port . use a different port as debugger address after closing all the chrome instance or restart the system

Also see if the port is in use and kill it (windows)

netstat -ano | findstr :PORT
kill PI
PDHide
  • 18,113
  • 2
  • 31
  • 46