PID of firefox process on windows/.net?

2,287 views
Skip to first unread message

SeleniuMaddog

unread,
Apr 15, 2011, 12:36:51 PM4/15/11
to webdriver
Hi,

Is there some tricky back-alley way to get the process-id of the
spawned firefox instance?
I'm using webdriver with .Net and firefox.

Thanks

Jim Evans

unread,
Apr 15, 2011, 3:34:08 PM4/15/11
to webdriver
Not with 100% certainty, unless you hack the FirefoxDriver source
code, specifically the FirefoxBinary class. I'm not sure I understand
why you'd want such a thing, but you could make an educated guess at
the process ID by cleverly using
System.Diagnostic.Process.GetProcessesByName().

Bill Ross

unread,
Apr 15, 2011, 8:06:53 PM4/15/11
to webd...@googlegroups.com
> Is there some tricky back-alley way to get the process-id of the
> spawned firefox instance?
> I'm using webdriver with .Net and firefox.

Not sure if it rises to the level of tricky, let alone
back-alley, but if you launched RC under cygwin, you'd
likely see the pid with 'ps -eaf'. I'm not sure if
cygwin tracks non-cygwin tasks, tend to doubt it. Just
a thought.

Bill

SeleniuMaddog

unread,
Apr 15, 2011, 11:54:01 PM4/15/11
to webdriver
While waiting for an answer I indeed patched the FirefoxDriver and
FirefoxBinary classes to expose the process.
I hate when things exist but are hidden behind privates. Now I will
have to do this with every version forever :-\

In case anyone is interested, I'm spawning multiple webdriver powered
firefox processes, I also interact with them using other tools (which
I run from the same code that runs the webdriver), I just need the pid
to tie everything together in a nice way.

Now that I'm thinking about it some more... if there's an about:config
setting that allows setting (or appending to) the window title - I
could use that to find the correct process... hmm... maybe that is a
better way to solve this.

Thanks for the answers!

QA_manager

unread,
Apr 18, 2011, 10:01:56 AM4/18/11
to webdriver
Please let us know what you learn and your best solution, so other
people can benefit from your knowledge.

SeleniuMaddog

unread,
Apr 18, 2011, 11:25:21 AM4/18/11
to webdriver
QA_manager - if the information exists, why not make it public?
I presume it is hidden because it is not possible to get this info on
all platforms/browsers, but why not expose it where it exists?

It'll take some for me to actually get to testing alternative methods
of accomplishing this, because I currently have a working solution.
But if anyone is interested - this is the path I would take:

1) Listing processes by title or other methods -
http://www.codeproject.com/KB/threads/ApplicationCheck_CS.aspx
2) Changing firefox title - http://kb.mozillazine.org/Rebranding_Firefox

Thank you

Jim Evans

unread,
Apr 18, 2011, 3:54:59 PM4/18/11
to webdriver
I thought I'd posted a reply to this over the weekend, but I suppose I
must not have.

Basically, the System.Diagnostics.Process object used to track the
Firefox process in the FirefoxDriver is an internal implementation
detail. I might be convinced that it should be exposed via a protected
property so that it could be accessed via a subclass, but please
realize that this is the first time anyone has asked for such a thing.
It's not part of the public cross-platform, cross-browser API, and as
such it is, and in my opinion ought to be, private.

I can forsee a day that we won't be using System.Diagnostics.Process
for tracking Firefox instances (cf. the new ChromeDriver checked into
the trunk of the project). In that instance, we would be put in the
untenable position of breaking an until-then public API because it
would no longer be applicable.

Regards,
--Jim

On Apr 18, 11:25 am, SeleniuMaddog <madd0g.co...@gmail.com> wrote:
> QA_manager - if the information exists, why not make it public?
> I presume it is hidden because it is not possible to get this info on
> all platforms/browsers, but why not expose it where it exists?
>
> It'll take some for me to actually get to testing alternative methods
> of accomplishing this, because I currently have a working solution.
> But if anyone is interested - this is the path I would take:
>
> 1) Listing processes by title or other methods -http://www.codeproject.com/KB/threads/ApplicationCheck_CS.aspx
> 2) Changing firefox title -http://kb.mozillazine.org/Rebranding_Firefox
> > > > Bill- Hide quoted text -
>
> - Show quoted text -

SeleniuMaddog

unread,
Apr 28, 2011, 12:47:30 AM4/28/11
to webdriver
Ok, so I have a good reason - recover from a browser crash.
Today I found a site in which a certain code always crashes the
browser.
I immediately thought how nice it would be to be able to query if the
browser still running by pid.

Webdriver just seems to timeout while trying to talk to the browser
(that's the exception I've seen, maybe it is somehow handled, I'm not
sure) - but the browser is not revived or anything.

Thanks

SeleniuMaddog

unread,
Apr 30, 2011, 5:41:55 PM4/30/11
to webdriver
Faulting application name: Firefox.exe, version: 1.9.2.4095, time
stamp: 0x4d852c95
Faulting module name: js3250.dll, version: 0.0.0.0, time stamp:
0x4d8523fd
Exception code: 0xc0000005
Fault offset: 0x0007cfc4

I don't even know if it's reproducible outside of my system, can
someone please check if the following crashes their firefox?
My browser always crashes when I run this code with the C# firefox
driver.

driver.Navigate().GoToUrl("http://www.whatismyip.com/");
driver.SwitchTo().DefaultContent();

//Close the ad-popup(s)
while (driver.GetWindowHandles().Count > 1)
{
var win = driver.GetWindowHandles().Last();
driver.SwitchTo().Window(win);
driver.Close();
}
driver.Manage().DeleteAllCookies();


//Thank you!
Reply all
Reply to author
Forward
0 new messages