Get PID of Browser launched by selenium

前端 未结 9 1558
闹比i
闹比i 2020-11-30 07:15

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

9条回答
  •  借酒劲吻你
    2020-11-30 07:52

    I solved it this way:

    I am on a Linux OS using Python to detect Firefox memory usage:

    import psutil
    
    # Get pid of geckodriver
    webdriver_pid = driver.service.process.pid
    
    # Get the process of geckodriver
    process = psutil.Process(webdriver_pid)
    
    # Get memory of geckodriver + firefox
    # Since memory is in bytes divide by 1024*1024 to obtain result in MB
    total_memory = sum([x.memory_info().rss/1048576 for x in process.children() + [process]])
    

提交回复
热议问题