Get Session Id

In cases where you want to uniquely identify the current test, you might want to use the session ID that BrowserStack generates automatically for each of your test runs.

You can use these sessions IDs to internally map with your test cases, or logging, or automatically raising a bug report.

You can use the WebDrivers’ API to retrieve BrowserStack’s session ID as follows:

// Start a remote browser with the desired capabilities
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

// ... run some tests

// Get the session ID
driver.getSessionId();

// ... do something with the session ID

// ... continue with your tests
driver.session_.then(function(sessionData) {
    console.log(sessionData.id_);
});
// For selenium version 2.48.2 and below -
var sessionIdProperty = typeof(RemoteWebDriver).GetProperty("SessionId", BindingFlags.Instance | BindingFlags.NonPublic);
SessionId sessionId = sessionIdProperty.GetValue(driver, null) as SessionId;
Console.WriteLine(sessionId.ToString());

// For selenium version 2.49.0 and above refer - https://github.com/browserstack/automate-csharp-samples/blob/master/retrieve-sessionId.cs
$web_driver->getSessionID();
driver.session_id
driver.session_id
$driver->id();

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback