0

I use ChromeDriver to create a Screenschot like

ChromeOptions options = new ChromeOptions();
options.AddArgument("headless"); 

var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
driver.Navigate().GoToUrl("http://192.168.15.104:12347/WebPortal/controlSystemInternal");

driver.Manage().Window.Size = new System.Drawing.Size(1800, 1100);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id("wait")));
var screenshot = (driver as ITakesScreenshot).GetScreenshot();
screenshot.SaveAsFile("c:\\temp\\screenshot.png");

ChromeDriver.exe locates in the Dicrectory of the executing assembly. This is working great on my developement-environment. But when I run this in the production-environment, I get the Exception

OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:58266/ bei OpenQA.Selenium.DriverService.Start()
bei OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) bei OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) bei OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) bei OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) bei OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout) bei OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)

The portnumbe in the Exception-Message differs always.

Does anyone have an idea whats going wrong there?

BennoDual
  • 5,865
  • 15
  • 67
  • 153

1 Answers1

0

1.The ChromeDriver and the Chrome major version of the Chrome browser may be different. You can synchronize them either manually (not recommended as you will need to do that every 1-3 months) or automatically - using WebDriverManager.
2. Check if there is another ChromeDriver process that is running, you should dispose/quit the driver after you stop using it. We are also using taskkill /f /im chromedriver.exe command when we are starting out tests to ensure that we start in clean state.

The port number is always different in our tests also, does not cause issues. But if the range of ports that are used by ChromeDriver on your production machine are not open, this could also be the cause for issues.

References:
OpenQA.Selenium.WebDriverException: 'Cannot start the driver service on http://localhost:20548/'
Getting chrome driver not in path when moving my selenium executable to another computer

K. B.
  • 3,342
  • 3
  • 19
  • 32