简体   繁体   中英

How to identify chromedriver.exe?

I have some RPA processes which use ChromeDriver to connect to specific instances of Chrome identified by its remote-debugging-port and a custom command arument for chrome which idenitifies the specific chrome instances as "from my program".

I have a program using Selenium ChromeDriver. I do not let ChromeDriver create the Chrome Instance, but rahter re-use an existing one. So when my program starts up it can find the specific Chrome I want to use, and connect a new ChromeDriver to it. The issue is that sometimes the ChromeDriver is left running stuck because I exited without Quitting it (this is development work - stuff happens!)

I would like to be able to somehow tag the ChromeDriver that was launched by my programs. Iti is easy to tage the Chrome instance - I just pass in any unique argument and it happily accepts it, as in "--originator=me", then I can go through the chrome processes, get their command line and know which Chrome is mine. But I do not know how to do this with ChromeDriver. Here are ideas I have that have not worked:

  1. Pass in a command line argument to chromedriver, but the only argument I see in the process is "port=12345"

  2. Get the Process ID of the chromedriver I just created. But I do not know how to ask the new driver for this, even though I have access to it.

Any ideas on how to identify a chromedriver that my process created, assuming that later on my program will be looking for this specific instance?

You can use a ChromeDriverService to create a ChromeDriver then give the service a LogPath. That LogPathcan be the identifier as long as it's a valid file name. Just like this:

var svc = ChromeDriverService.CreateDefaultService();
svc.LogPath = LogPath
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(svc, options);

Then if you want to find the specific ChromeDriver, just find the windows process with this command-line argument. In this case we really don't care about the contents of that file itself, just the fact that the magic word is now programmatically discoverable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM