栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C# > C#教程

c# 从内存中释放Selenium chromedriver.exe

C#教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c# 从内存中释放Selenium chromedriver.exe

背景

我设置了一个c#代码来运行Selenium chromedriver.exe.在运行结束时,我有browser.close()来关闭实例。(browser = webdriver.Chrome())我相信它应该从内存中释放chromedriver.exe(我在Windows 7上)。但是每次运行后,内存中仍有一个chromedriver.exe实例。

问题窥探

从理论上讲,调用browser.Quit将关闭所有浏览器选项卡并终止进程。

但是,在我的情况下,我无法做到这一点 - 因为我并行运行多个测试,我不想进行一次测试来关闭其他人的窗口。因此,当我的测试完成运行时,仍有许多“chromedriver.exe”进程在运行。

解决办法
public override void DoJob(IJobExecutionContext context, ILifetimeScope scope, string[] args)
    {
      Console.WriteLine(nameof(LoginReptiles1688Job) + " 开始-------------------");
      ChromeOptions options = null;
      IWebDriver driver = null;
      try
      {
 options = new ChromeOptions();
 options.AddArguments("--ignore-certificate-errors");
 options.AddArguments("--ignore-ssl-errors");
 var listcookie = cookieHelp.Getcookie();
 if (listcookie != null)
 {
   // options.AddArgument("headless");
 }
 ChromeDriverService service = ChromeDriverService.CreateDefaultService(System.Environment.CurrentDirectory);
 service.HideCommandpromptWindow = true;
 driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(120));
 var setLoginStatus = scope.Resolve();
 IReptilesImageSearchService _reptilesImageSearchService = scope.Resolve();
 CrawlingWeb(_reptilesImageSearchService, driver);
 CrawlingWebShop(_reptilesImageSearchService, driver);
      }
      catch (Exception ex)
      {
 throw ex;
      }
      finally
      {
 driver?.Close(); // Close the chrome window
 driver?.Quit(); // Close the console app that was used to kick off the chrome window
 driver?.Dispose(); // Close the chromedriver.exe

 driver = null;
 options = null;
 detailtry = 0;
 shoptry = 0;
 Console.WriteLine(nameof(LoginReptiles1688Job) + " 结束-------------------");
      }
    }

在C#控制台应用程序中使用了chrome驱动程序,只有在将所有三种方法一起调用后才能清理延迟进程。

以上就是c# 从内存中释放Selenium chromedriver.exe的详细内容,更多关于c# 内存中释放Selenium 的资料请关注考高分网其它相关文章!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/121516.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号