title: Get Session ID for a Selenium RemoteWebDriver in C#
body: <p>I'm trying to get a session id for a test being run on the SauceLabs cloud, but I can't seem to access it. </p>
  
  <p>I've tried the following approaches:</p>
  
  <pre><code>//Returns null
  var sessionId = (string)((RemoteWebDriver)driver).Capabilities.GetCapability("webdriver.remote.sessionid");
  
  //Will not compile
  sessionId = ((RemoteWebDriver)driver).SessionId; //This is protected. 
  </code></pre>
  
  <p>The second approach is particularly confusing. It's a protected property, but if I can only access this from a derived class, then it's essentially useless for what I need.</p>
  
  <p><img src="https://i.stack.imgur.com/jhQTR.png" alt="Session ID"></p>
  
  <p>Any help is appreciated.</p>
  
  <p>In order for this to work, I had to create a class derived from <code>RemoteWebDriver</code> and then define a getter method. For example:</p>
  
  <pre><code>class  CustomeRemoteDriver : RemoteWebDriver
  {
  
      public CustomeRemoteDriver(ICapabilities desiredCapabilities):base(desiredCapabilities)
      {
      }
  
      public CustomeRemoteDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities):base(commandExecutor, desiredCapabilities)
      {
      }
  
      public CustomeRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities):base(remoteAddress, desiredCapabilities)
      {
      }
  
      public CustomeRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout):base(remoteAddress, desiredCapabilities, commandTimeout)
      {
      }
  
      public string GetSessionId()
      {
          return base.SessionId.ToString();
      }
  } 
  </code></pre>