0

I get the following object from the selenium hub and I'm dumping the result to the console to see the data structure by doing the following

 browser.getCapabilities().then(function (capabilities) {

        console.log(capabilities);

    });

and the object being printed out it is

{ caps_:
   { applicationCacheEnabled: false,
     rotatable: false,
     mobileEmulationEnabled: false,
     chrome: { userDataDir: '/var/folders/tc/89n0t1qs5p3fyw_n9hk1x7fc0000gn/T/.org.chromium.Chromium.97EFOo' },
     takesHeapSnapshot: true,
     databaseEnabled: false,
     handlesAlerts: true,
     hasTouchScreen: false,
     version: '50.0.2661.86',
     platform: 'MAC',
     browserConnectionEnabled: false,
     nativeEvents: true,
     acceptSslCerts: true,
     'webdriver.remote.sessionid': 'd94af299-7fdc-4810-a42c-37a652a2248c',
     locationContextEnabled: true,
     webStorageEnabled: true,
     browserName: 'chrome',
     takesScreenshot: true,
     javascriptEnabled: true,
     cssSelectorsEnabled: true } }

I can get all the properties except for the one I want which is 'webdriver.remote.sessionid'. I'm not sure how to get that since it starts with a single quote. I grab the others with

 console.log(capabilities.caps_.cssSelectorsEnabled)

how can I get the session id?

user3626708
  • 727
  • 2
  • 8
  • 24
  • 4
    Use `capabilities.caps_['webdriver.remote.sessionid']` – Tushar Apr 22 '16 at 04:58
  • @Tushar Your answer is correct. Can you explain how square bracket worked for this case, as we are used to apply square brackets only for arrays rather than objects? – Ganesh Babu Apr 22 '16 at 05:05
  • @GaneshBabu You can read [MDN docs](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors#Bracket_notation). Bracket notation is used to get the value of property by name, **array is also an object** thus it works both on arrays and objects. – Tushar Apr 22 '16 at 05:11
  • @Tushar Object is equal to Associative array. Haven't heard of it before. Thanks for your clarification. – Ganesh Babu Apr 22 '16 at 05:16

0 Answers0