【问题标题】:Close Chrome Web Driver on Windows Form Closing关闭 Windows 窗体上的 Chrome Web 驱动程序
【发布时间】:2018-05-09 16:02:02
【问题描述】:

我有一个相对简单的问题,但我似乎无法在任何地方找到答案。每当我在 Selenium Chrome Web 驱动程序打开的情况下关闭我的 Windows 窗体时,它都会关闭 Windows 窗体/应用程序,但让 Chrome 控制台和浏览器保持打开状态。有什么方法可以使用 driver.Quit() 或 .Close();表格何时关闭?类似于我下面的示例。

    private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        driver.Quit();
    }

【问题讨论】:

    标签: c# google-chrome selenium selenium-webdriver


    【解决方案1】:

    试试下面的。

    driver.Quit();
    driver = null;
    

    【讨论】:

      【解决方案2】:

      问题是当你按下关闭按钮时,关闭表单的事件没有被捕获。

      您必须订阅 FormClosing 事件并在驱动程序上调用 Quit 方法。

          public Form1()
          {
              // (...)
              this.FormClosing += this.Form1_FormClosing;
          }
      
          private void Form1_FormClosing(object sender, FormClosingEventArgs e)
          {
              driver.Quit();
              Environment.Exit(0);
          }
      

      请注意,当您使用 F5 运行应用程序时,驱动程序的控制台将关闭,但当您按 CTRL F5 运行时不会关闭。

      【讨论】:

        猜你喜欢
        • 2021-01-25
        • 1970-01-01
        • 2022-01-28
        • 1970-01-01
        • 1970-01-01
        • 2016-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多