c# 从内存中释放Selenium chromedriver.exe
作者:UP技术控
这篇文章主要介绍了c# 从内存中释放Selenium chromedriver.exe的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下
我设置了一个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;
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<ISetLoginStatus>();
IReptilesImageSearchService _reptilesImageSearchService = scope.Resolve<IReptilesImageSearchService>();
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 的资料请关注脚本之家其它相关文章!
您可能感兴趣的文章:
C#中Timer定时器类的简单使用
2022-05-05
C#实现文本读取的7种方式
2022-05-05
WinForm使用DecExpress控件中的ChartControl插件绘制图表
2022-05-05
C#中的WebRequest与WebResponse抽象类、DNS静态类、Ping类介绍
2022-05-05
C#使用CefSharp控件实现爬虫
2022-05-05
在C#中使用MongoDB数据库
2022-05-05
C#操作SQLite数据库方法小结
2022-05-05
基于C#实现宿舍管理系统
2022-05-05
美国设下计谋,用娘炮文化重塑日本,已影响至中国
2021-11-19
时空伴随者是什么意思?时空伴随者介绍
2021-11-09
工信部称网盘企业免费用户最低速率应满足基本下载需求,天翼云盘回应:坚决支持,始终
2021-11-05
2022年放假安排出炉:五一连休5天 2022年所有节日一览表
2021-10-26
电脑版
-
返回首页
2006-2024 脚本之家 JB51.Net , All Rights Reserved.
苏ICP备14036222号