Selenium SessionID

Best practices, code snippets for common functionality, examples, and guidelines.
BSullivan
Posts: 32
Joined: Thu Jun 04, 2015 6:31 pm
Location: HorseHeads NY
Contact:

Selenium SessionID

Post by BSullivan » Fri Feb 15, 2019 3:56 pm

Is there currently any way to get the SessionID of a Webdriver endpoint that is currently running a test? I would like to capture this so that I can pass it along on a "curl" request to get some metadata from the hosted Selenium grid service that we use.

Any ideas?

Thanks in advance.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Selenium SessionID

Post by RobinHood42 » Thu Feb 21, 2019 1:08 pm

Hey,

I came up with the following code:
var webdriver = Host.Current.TryGetAsWebDriverEndpoint();
        	var drivers = webdriver.WebDrivers;
        	
        	foreach (var tmp in drivers) {
        		var driver = tmp as OpenQA.Selenium.Remote.RemoteWebDriver;
        		var id = driver.SessionId;
        		
        		Console.WriteLine("SessionID " + id);
        	}
        	
Hope this helps :mrgreen:

Cheers,
Robin

BSullivan
Posts: 32
Joined: Thu Jun 04, 2015 6:31 pm
Location: HorseHeads NY
Contact:

Re: Selenium SessionID

Post by BSullivan » Thu Feb 21, 2019 4:36 pm

Awesome.

Thank you!!!