Selenium Webdriver in VS 2015 and C# - strange SocketException when accessing web server

21 views
Skip to first unread message

Den Fyren

unread,
Jan 10, 2018, 6:41:25 AM1/10/18
to Selenium Users
I've got a small application using Selenium WebDriver to access a web page, as well as AutoIt to handle the login prompt (since normal authentication by sending the username/password in the URL doesn't work). When I run the code normally in VS's debugger, it works fine, but throws some exceptions. If I tell it to break on SocketException, I get some disturbing info:

The Selenium driver code:

var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;

try {
     driver = new ChromeDriver(driverService, new ChromeOptions());
} catch (Exception ex) {
     if (ex is NullReferenceException || ex is System.Net.Sockets.SocketException) {
          return;
     }
     throw;
}

driver.Navigate().GoToUrl(url);


This code results in a 

System.Net.Sockets.SocketException ("No connection could be made because the target machine actively refused it")


Now, this is quite strange. If I don't break at the SocketException, ChromeDriver starts and navigates to the page (and logs in) without problems. Also, the notion that the target machine should actively refuse the connection is absurd, since the driver is accessing a web server which is definitely accepting connections (proven by the fact that it works if not breaking for the exception, and by accessing the page manually).
Reply all
Reply to author
Forward
0 new messages