Reputation:
I am trying to parse a multi-value cookie using the Selenium IDE. I have this as my Tracking Cookie Value: G=1&GS=2&UXD=MY8675309=&CC=234&SC=3535&CIC=2724624
So far I have simply captured the full cookie into a Selenium variable with the standard StoreCookieByName command:
storeCookieByName Tracking Tracking
However I want to get a particular sub element of the cookie for my test, such as the UXD value of MY8675309.
I have tried using Javascript to parse and all but have had no luck with it and the StoreCookieByName value.
Any help would be appreciated.
Upvotes: 2
Views: 3075
Reputation: 3685
Here's a generalized solution. This is a bit clumsy, but I can't think of a more concise method:
// Declare variables.
var subElements = cookieString.split("&");
var subElemPairs = new Array();
var subNameValues = new Array();
// Obtain sub-element names and values.
for (i = 0; i < subElements.length; i++)
{
subElemPairs[i] = subElements[i].split("=");
}
// Place sub-element name-value pairs in an associative array.
for (i = 0; i < subElemPairs.length; i++)
{
subNameValues[subElemPairs[i][0]] = subElemPairs[i][1];
}
// Example sub-element value request.
var requestedElemName = "SC";
var resultingElemValue = subNameValues[requestedElemName];
Upvotes: 1
Reputation: 3685
If the Tracking Cookie Value is a string, then:
var subElements = cookieString.split("&");
var UXDValue = subElements[2].substring(4);
Upvotes: 1