static void Main()
// Ensure geckodriver.exe is in the same folder as your .exe or in PATH var options = new FirefoxOptions(); options.AddArgument("--headless"); // optional: headless mode static void Main() // Ensure geckodriver
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"D:\drivers"); service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; var driver = new FirefoxDriver(service); Sometimes a corrupted Firefox profile causes the driver to hang on startup. Root Cause Analysis The error indicates a port
Below, I break down exactly why this happens and the 7 most effective fixes. OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:xxxx/ ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted. Root Cause Analysis The error indicates a port conflict or driver process failure . The geckodriver tries to bind to a port on localhost , but something is blocking it. var driver = new FirefoxDriver(service)
taskkill /F /IM geckodriver.exe