0

We use ChromeDriver in C# to connect to existing instances of Chrome that have the remote debugging port 9222 set. Here is how we connect:

    var svc = ChromeDriverService.CreateDefaultService(path);
    ChromeOptions options = new ChromeOptions();
    options.DebuggerAddress = "127.0.0.1:9222";
    var driver = new ChromeDriver(svc, options);
    
    var url = driver.Url;

The problem is that the value of driver.Url is not what it used to be when using ChromeDriver version 88.
At that point and all earlier versions, driver.Url was the value of the URL for the current active tab in Chrome. So if Chrome had five tabs open and tab 4 is active, the Url was that of tab 4. And that made sense.

Once we upgraded to version 90 that is no longer the case. It appears that the value of Url is... well it's not clear. Sometimes the last active tab, sometimes some other tab, sometimes the first. I do not see a pattern.

Is this an error in ChromeDriver? In the past, whatever was the active tab was the one that driver.Url yielded. Now it's indeterminate which wreaks havoc with our code.

Update: If I have two tabs open, then the driver.Url and driver.Title are for the tab that was just prior active. So always the other tab. With 3 tabs it may be the 2nd to the last active tab. This feels like a off-by-one error within an internal array of tabs.

Daniel Williams
  • 8,912
  • 15
  • 68
  • 107

1 Answers1

1

I had the same problem. I solved it using the method suggested here

    ChromeDriverService driverService = 
    ChromeDriverService.CreateDefaultService();

     var options = new ChromeOptions();
     options.DebuggerAddress = "127.0.0.1:9222";
     var driver = new ChromeDriver(driverService, options);
  
     driver.SwitchTo().Window(driver.WindowHandles[0]); // Switch to the recently opened tab

     MessageBox.Show("driver.Url: " + driver.Url);
vadus
  • 21
  • 4
  • Thanks. Chrome changes so fast that we're now on ChromeDriver 95 and Chrome 96. Except for the clients who are stuck on 92 because their sites do not support proper encryption! This feels like it may never end. – Daniel Williams Nov 21 '21 at 19:27
  • It seems to me that this is not a change, but a bug. It's strange that it's still almost nowhere mentioned and not fixed – vadus Nov 23 '21 at 18:23