获取 selenium 启动的浏览器的 PID [英] Get PID of Browser launched by selenium

查看:133
本文介绍了获取 selenium 启动的浏览器的 PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取 selenium 启动的浏览器的 PID.有什么办法可以完成吗?

I would like to get the PID of the browser launched by selenium. Is there any way to get it done?

推荐答案

使用Python API,很简单:

Using the Python API, it's pretty simple:

from selenium import webdriver
browser = webdriver.Firefox()
print browser.binary.process.pid
# browser.binary.process is a Popen object...

如果您使用的是 Chrome,它会稍微复杂一些,您需要通过 chromedriver 进程:

If you're using Chrome, it's a little more complex, you go via a chromedriver process:

c = webdriver.Chrome()
c.service.process # is a Popen instance for the chromedriver process
import psutil
p = psutil.Process(c.service.process.pid)
print p.get_children(recursive=True)

这篇关于获取 selenium 启动的浏览器的 PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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