from contextlib import suppress
import psutil
from selenium.webdriver import Chrome
driver = Chrome()
driver.get('https://stackoverflow.com/questions/59072010/is-there-a-way-to-know-what-chrome-process-comes-from-chromedrive-using-python')
for process in psutil.process_iter():
if process.name() == 'chrome.exe' and '--test-type=webdriver' in process.cmdline():
with suppress(psutil.NoSuchProcess):
process.kill()
import psutil
for process in psutil.process_iter ():
if process.name() == 'chrome.exe':
Name = process.name ()
ID = process.pid
print ("Process name =", Name ,",","Process ID =", ID)
2条答案
按热度按时间yptwkmov1#
如果我理解你的问题,你可以使用psutil模块来检查运行的chrome进程,杀死命令行参数中有“webdriver”的进程。
xmakbtuz2#