Selenium 可以在一个浏览器中使用多线程吗? [英] Can Selenium use multi threading in one browser?

查看:70
本文介绍了Selenium 可以在一个浏览器中使用多线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多线程中测试网络,但是当我打开太多 chromedriver 时,它们会使用太多内存.我可以在一个浏览器中使用多线程吗?

I want to test a web in multi threading but when I open too many chromedrivers they use too much memory. Can I use multi threading in one browser?

推荐答案

WebDriver 不是线程安全的.线程安全问题不在您的代码中,而在实际的浏览器绑定中.他们都假设一次只有一个命令(例如,就像一个真正的用户).但另一方面,您可以为每个线程实例化一个 WebDriver 实例,但它会启动多个浏览器,从而消耗更多内存.

WebDriver is not thread-safe. The issue of thread-safety isn't in your code but in the actual browser bindings. They all assume there will only be one command at a time (e.g. like a real user). But you can on the other hand instantiate one WebDriver instance for each thread but it will launch multiple browsers which will consume more memory.

这篇关于Selenium 可以在一个浏览器中使用多线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆