selenium大量并发连接驱动超时

我的业务是根据数据生成一大片报表图,组成一个word文档,量大概10~100之间,挨个执行太慢了,15分钟左右,为了加快速度使用了多线程,而多线程又被机器速度限制,一旦跑的多了,就会有线程被挂起,这时就会报连不上驱动的问题。找了大量文章,都是在写访问超时时间,没有写驱动超时的。。。

解决方案

使用ChromeDriverServiceChromeOptions创建页面对象指定连接驱动超时时间,设置为5分钟,

java 复制代码
	//System.setProperty(global.getConfig("webDriver.driverName"), getUrlStr(global.getConfig("webDriver.driverPath")));
	System.setProperty("webdriver.chrome.driver", "D:/developkit/driver/chromedriver.exe");
	ChromeOptions chromeOptions = new ChromeOptions();
	//无头模式
	chromeOptions.setHeadless(false);
	//设置浏览器完整路径,有时会报找不到浏览器的问题,指定路径
	chromeOptions.setBinary("D:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
	
	Duration duration = Duration.of(5, ChronoUnit.MINUTES);//5分钟超时时间 - 驱动连接超时时间
	ChromeDriverService service = new ChromeDriverService.Builder()
                //超时时间
                .withTimeout(duration)
                //执行驱动,由chromeOptions提供
                //.usingDriverExecutable(getUrl(global.getConfig("webDriver.driverPath")))
                .build();
//        service.start();
	return new ChromeDriver(service, chromeOptions);
	
相关推荐
0思必得03 小时前
[Web自动化] 爬虫之API请求
前端·爬虫·python·selenium·自动化
测试老哥4 小时前
软件测试之功能测试详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
0思必得05 小时前
[Web自动化] 爬虫之网络请求
前端·爬虫·python·selenium·自动化·web自动化
安然无虞7 小时前
「深入理解多线程编程」再谈线程
爬虫·python·测试工具
深蓝电商API8 小时前
Selenium 与 BeautifulSoup 结合解析页面
爬虫·python·selenium·beautifulsoup
深蓝电商API10 小时前
Selenium 绕过 Cloudflare 反爬检测
爬虫·python·selenium
0思必得010 小时前
[Web自动化] 爬虫实例(获取时光网某个年度电影数据)
前端·爬虫·python·selenium·自动化
@zulnger12 小时前
selenium 自动化测试工具实战项目(客户)
selenium·测试工具·自动化
奇遇0.0048713 小时前
tryhackme-Wireshark:基础知识
网络·测试工具·wireshark