'No chrome process with a MainWindowTitle
I have made a small code snippet for getting the process id of the current running Google Chrome (chrome.exe), as we use it for automation. However sometimes, the clients running the automation get an error where there are no processes running with a non-empty MainWindowTitle property.
It is my understanding that there should always be exactly one chrome process with a non-empty MainWindowTitle (all the others are blank), when Google Chrome is running. Am I missing some? Can you have chrome processes where all the MainWindowTitle's are blank? And if so, how do you reproduce it?
This is the code I use to ge the process id:
var chromeProcesses = Process.GetProcessesByName("chrome");
if (chromeProcesses.Length == 0)
throw new InvalidOperationException("Failed to find any Chrome processes.");
var primaryProcess = chromeProcesses.FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle));
if (primaryProcess == null)
throw new InvalidOperationException("None of the Chrome processes had a non-empty 'MainWindowTitle'.");
var processId = primaryProcess.Id;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
