0

How can I check how much memory is used by an IE11 process that is associated with a given InternetExplorerDriver in Selenium?

I'd like to restart IE11 if its memory usage exceeds a certain value (for example 1 GB).

Right now I'm thinking on using Get PID of Browser launched by selenium (if applicable to C#) and then Getting a process's ram usage.

Would that be the correct approach?

enter image description here

Edit: Turns out Get PID of Browser launched by selenium works only for Firefox or Chrome.

sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

0

I havn't found any solution about this and I think we can't achieve this by using selenium. Selenium does not monitor any resource usage, it is just a way to emulate user actions. I think you should try other ways to check browser memory usage or check other behavior in selenium. For example, you could use Windows tasklist command to get the memory usage of the browser.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
0

In the end I resorted to a workaround. I restart IE11 if there is any iexplore.exe process that has a working set above 800 MB.

foreach (Process proc in Process.GetProcessesByName("iexplore"))
{
    // Check if IE is above 800 MB.
    if (proc.WorkingSet64 > 800*1024*1024)
    {
        driver.Close();
        driver.Quit();
        foreach (Process p in Process.GetProcessesByName("iexplore")) { try { p.Kill(); } catch { } }
        foreach (Process p in Process.GetProcessesByName("IEDriverServer")) { try { p.Kill(); } catch { } }
        driver = new InternetExplorerDriver(options);
        break;
    }
}
sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • Thanks for posting the solution for this issue. You can mark your answer as an accepted answer. It can help other community members in future in similar kind of issues. Thanks for your understanding. – Yu Zhou Jun 22 '20 at 08:32