【问题标题】:WebDriverException when Instantiate ChromeDriver实例化 ChromeDriver 时出现 WebDriverException
【发布时间】:2021-08-29 08:27:42
【问题描述】:

我使用 ChromeDriver 创建一个类似的屏幕截图

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 位于执行程序集的目录中。 这在我的开发环境中非常有用。但是当我在生产环境中运行它时,我得到了异常

OpenQA.Selenium.WebDriverException:无法启动驱动程序服务 http://localhost:58266/ bei OpenQA.Selenium.DriverService.Start()
北 OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令 commandToExecute) bei OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute, Dictionary`2 参数) bei OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities 所需能力)贝 OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) bei OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService 服务, ChromeOptions 选项,TimeSpan 命令Timeout) bei OpenQA.Selenium.Chrome.ChromeDriver..ctor(字符串 chromeDriverDirectory,ChromeOptions 选项)

异常消息中的端口号总是不同。

有人知道那里出了什么问题吗?

【问题讨论】:

    标签: c# selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    1.ChromeDriver和Chrome浏览器的Chrome主版本可能不同。您可以手动同步它们(不推荐,因为您需要每 1-3 个月进行一次)或自动同步 - 使用 WebDriverManager
    2. 检查是否有其他 ChromeDriver 进程正在运行,停止使用驱动程序后应丢弃/退出驱动程序。我们在开始测试时也使用了taskkill /f /im chromedriver.exe 命令,以确保我们以干净的状态开始。

    在我们的测试中端口号总是不同的,不会导致问题。但是,如果您的生产机器上 ChromeDriver 使用的端口范围未打开,这也可能是问题的原因。

    参考资料:
    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

    【讨论】:

      猜你喜欢
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 2017-10-02
      • 2013-10-24
      • 1970-01-01
      相关资源
      最近更新 更多