How do I parse a variable or multi value cookie in

2019-05-23 14:45发布

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.

2条回答
一夜七次
2楼-- · 2019-05-23 15:20

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];
查看更多
疯言疯语
3楼-- · 2019-05-23 15:37

If the Tracking Cookie Value is a string, then:

var subElements = cookieString.split("&");
var UXDValue = subElements[2].substring(4);
查看更多
登录 后发表回答