I have extracted the following code from selenium IDE.(c# remote control)
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Thr
Make sure the remote machine on which scripts are to be run is up and working. Secondly make sure chrome driver and chrome is update on it. Lastly no firewall is blocking ur access to remote machine.
PS: Manually close the selenium server and restart it.
I got this because a part of my code held a reference to a stale driver.
var driver1 = new OpenQA.Selenium.Firefox.FirefoxDriver();
driver1.Close();
driver1.Quit();
driver1.Dispose();
var x = driver1.FindElements(...);
I get the same error, but on a different line of code. Hopefully this might help someone somewhere even if it doesn't answer the initial question.
public override void SetupTest()
{
Driver = new FirefoxDriver();
base.SetupTest();
}
I'm using the WebDriver (I don't run the Selenium server), and the constructor of FirefoxDriver throws the Exception.
Sometimes I get this exception:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: No connection could be made because the target machine actively refused it
with this call stack:
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.ConnectToBrowser(System.TimeSpan timeToWait) Line 247 C#
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start() Line 98 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.StartClient() Line 237 C#
WebDriver.dll!OpenQA.Selenium.Remote.RemoteWebDriver.RemoteWebDriver(OpenQA.Selenium.Remote.ICommandExecutor commandExecutor, OpenQA.Selenium.ICapabilities desiredCapabilities) Line 89 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxBinary binary, OpenQA.Selenium.Firefox.FirefoxProfile profile, OpenQA.Selenium.ICapabilities capabilities, System.TimeSpan commandTimeout) Line 172 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxBinary binary, OpenQA.Selenium.Firefox.FirefoxProfile profile, System.TimeSpan commandTimeout) Line 167 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxBinary binary, OpenQA.Selenium.Firefox.FirefoxProfile profile) Line 154 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxProfile profile) Line 132 C#
SetupTest() Line 513 C#
Sometimes I get this exception:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted
with this call stack:
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.DetermineNextFreePort(string host, int port) Line 161 C#
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start() Line 88 C#
[same as above]
But one thing I didn't realize at first is that if you continue execution (F5), everything is fine. The Exception must be handled in the WebDriver.
The only thing is that I had the DEBUG/Exceptions/CLR Exceptions: Thrown [checked]. Just uncheck that and everything runs without throwing/breaking. Took me a while to realize that. Leftovers of a previous debugging session...
To add more clarity for the readers: Start selenium server using the followings basic steps:
This is the way i do it, the structure of my class.
[TestFixture, Parallelizable(ParallelScope.None)]
public class UserTest : BaseTestClass
{
[SetUp]
public void SetUp()
{
ChromeOptions options = new ChromeOptions();
//options.AddArgument("--headless");
options.AddArgument("--start-maximized");
var driver = new ChromeDriver(options);
WebDriver = WebDriverExtended.InitWebDriver(driver, driver.Url);
WebDriver.Start();
}
[TearDown]
public void Cleanup()
{
//Dispose after every single test, fixed the problem.
WebDriver.Close();
WebDriver.Quit();
WebDriver.Dispose();
}
[Test]
public void LoginTest()
{
//My test ...
}
}
I am currently using Selenium.Support v3.6.0 and Selenium.WebDriver v3.6.0. Disposing the webdriver fixed my problem
No connection could be made because the target machine actively refused it 127.0.0.1:4444
For me, this problem was solved by changing settings within Chrome, as follows: