如何在Selenium中解析变量或多值cookie? [英] How do I parse a variable or multi value cookie in Selenium?

查看:100
本文介绍了如何在Selenium中解析变量或多值cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium IDE解析多值cookie。我将此作为我的跟踪Cookie值:G = 1& GS = 2& UXD = MY8675309 =& CC = 234& SC = 3535& CIC = 2724624

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

所以我已经使用标准的StoreCookieByName命令将完整的cookie捕获到Selenium变量中:

So far I have simply captured the full cookie into a Selenium variable with the standard StoreCookieByName command:


storeCookieByName
跟踪
跟踪

storeCookieByName Tracking Tracking

但是我想为我的测试获取cookie的特定子元素,例如MY8675309的UXD值。

However I want to get a particular sub element of the cookie for my test, such as the UXD value of MY8675309.

我已经尝试使用Javascript进行解析,但所有人都没有运气和StoreCookieByName值。

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.

推荐答案

这是一个通用的解决方案。这有点笨拙,但我想不出更简洁的方法:

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];

这篇关于如何在Selenium中解析变量或多值cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆