c# 從內(nèi)存中釋放Selenium chromedriver.exe
背景
我設置了一個c#代碼來運行Selenium chromedriver.exe.在運行結束時,我有browser.close()來關閉實例。(browser = webdriver.Chrome())我相信它應該從內(nèi)存中釋放chromedriver.exe(我在Windows 7上)。但是每次運行后,內(nèi)存中仍有一個chromedriver.exe實例。
問題窺探
從理論上講,調(diào)用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<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驅動程序,只有在將所有三種方法一起調(diào)用后才能清理延遲進程。
以上就是c# 從內(nèi)存中釋放Selenium chromedriver.exe的詳細內(nèi)容,更多關于c# 內(nèi)存中釋放Selenium 的資料請關注腳本之家其它相關文章!
相關文章
C#語法糖(Csharp Syntactic sugar)大匯總
首先需要聲明的是“語法糖”這個詞絕非貶義詞,它可以給我?guī)矸奖?,是一種便捷的寫法,編譯器會幫我們做轉換;而且可以提高開發(fā)編碼的效率,在性能上也不會帶來損失。這讓java開發(fā)人員羨慕不已,呵呵。2010-06-06C# DataTable中查詢指定字段名稱的數(shù)據(jù)
這篇文章主要介紹了C# DataTable中查詢指定字段名稱的數(shù)據(jù),本文直接給出實例代碼,簡單易懂,需要的朋友可以參考下2015-06-06C#動態(tài)生成DropDownList執(zhí)行失敗原因分析
這篇文章主要介紹了C#動態(tài)生成DropDownList執(zhí)行失敗原因分析,以一個實例形式分析了C#動態(tài)生成DropDownList的相關注意要點與使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03C#中使用Join與GroupJoin將兩個集合進行關聯(lián)與分組
這篇文章主要介紹了C#中使用Join與GroupJoin將兩個集合進行關聯(lián)與分組,文中分別對Join和GroupJoin的用法進行詳細說明,需要的朋友可以參考下2017-12-12