我设置了一个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.在运行结束时,我有browser.close()来关闭实例。(browser = webdriver.Chrome())我相信它应该从内存中释放chromedriver.exe(我在Windows 7上)。但是每次运行后,内存中仍有一个chromedriver.exe实例。问题窥探从理论上讲,调用browser.Quit将关闭所有浏览器选项卡并终止进程。但是,在我的情况下,我无法做到这一点 - 因为我并行运行多
1 selenium安装
可以直接使用pip 安装。如果要快速,可以配合镜像
pip install --user selenium -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
2 chromedriver.exe安装
使用selenium配合webdriver使用。需要安装chromedriver.exe(如果使用谷歌浏览器的话)
首先查看自己浏览器的版本
然后去下载符合版本的chromedriver
最近服务器经常卡死导致有些采集服务没有运行,查询linux发现有大量的chromedriver进程,想起最近有个采集使用close关闭chrome,没有使用quit关闭chrome
1.参看资料
1.1 close方法是关闭当前窗口
driver实例正在操作的页面,叫当前。如果当前窗口只有一个tab,那么这个close方法就相当于关闭了浏览器
1.2quit方法是直接退出并关闭所有关联的tab窗口
完全关闭浏览器,是完全的退...
selenium关闭窗口有两个方法,close与quit,我们稍作研究便知道这两个方法的区别。1.看源码或API这是close()的说明:
Closes the current window.
关闭当前窗口。
这是quit()的说明:
Quits the driver and closes every associated window.
退出驱动并关闭所有关联的窗口。
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=" + "zh-CN");
WebDriver driver = new ChromeDriver(options);
ChromeDriver设置启动chrome为默认用户的配置信息(包括书签、...
换成chrome浏览器,执行测试脚本,报如下错误
[0.000][INFO]: ChromeDriver 23.0.1240.0 E:\workspace\testng\res\chromedriver.exe
[0.748][FINE]: Initializing session with capabilities {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [ ],
用selenium进行web页面自动化测试时,前段时间还测试得好好的,今天用selenium打开谷歌浏览就提醒chromedriver.exe停止运行。
突然想到前段时间系统帮我自动更新了浏览器版本。
解决方式:
1:查看浏览器版本(在Chrome的地址栏输入Chrome://version可以直接查看Chrome浏览器的版本信息)
2:如果浏览器版本太
selenium:你必须知道的七件事
原文链接:https://www.lucidchart.com/techblog/2015/07/21/selenium-7-things-you-need-to-know-2/
译者的话:
本文的作者就职于Lucid,如文中所述他们有着一套比较成熟的基于selenium的自动化测试工具。这得益于他们对于自动化测试的重视,因为只有自动化
在linux上面通过selenium的webdriver抓取数据的时候需要正确的关闭浏览器,不然就会出现内存泄漏的问题,注意下面的close和quir都需要加上去,其中close是关闭chromium,而quit则是关闭chromedriver的例如:simulated_browser = webdriver.Chrome()
simulated_browser.get("www.baidu.com
如果您已经将Selenium打包成可执行文件,但运行时找不到“chromedriver.exe”,可能是因为可执行文件无法找到ChromeDriver的路径。您可以尝试以下解决方案之一:
1. 将ChromeDriver添加到系统路径中:将ChromeDriver所在文件夹的路径添加到系统环境变量中。这样,可执行文件就能找到ChromeDriver了。
2. 在代码中设置ChromeDriver路径:在可执行文件中,您可以在代码中添加设置ChromeDriver路径的代码,例如:
```python
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r"path/to/chromedriver.exe")
请将“path/to/chromedriver.exe”替换为ChromeDriver的实际路径。这样,可执行文件就能找到ChromeDriver了。
希望这些解决方案可以帮助您解决问题。