Is there a way to extract a variable or a cookie with multiple values in Selenium?

I need assistance in extracting a specific value from a multi-value cookie using the Selenium IDE. The cookie's Tracking Cookie Value is as follows: G=1&GS=2&UXD=MY8675309=&CC=234&SC=3535&CIC=2724624

Currently, I have stored the entire cookie in a Selenium variable using the StoreCookieByName command:

storeCookieByName Tracking Tracking

However, my goal is to extract a particular sub-element of the cookie for testing purposes - specifically, the UXD value of MY8675309.

I attempted to use Javascript for parsing, but have been unsuccessful with both this method and the StoreCookieByName function.

If anyone can provide guidance on how to achieve this, it would be greatly appreciated.

Answer №1

In the case that the Tracking Cookie Value happens to be a string:

Let's split the cookieString into its subElements using the "&" separator.
Next, we will extract the UXDValue by taking a substring starting from index 4 of subElements[2].

Answer №2

Below is a solution that provides a more streamlined approach to handling sub-element names and values:

// Initialize variables.
var elements = cookieString.split("&");
var elementPairs = {};
var nameValues = {};

// Extract sub-element names and values.
for (i = 0; i < elements.length; i++)
{
    elementPairs[i] = elements[i].split("=");
}

// Store sub-element name-value pairs in a map.
for (i = 0; i < elementPairs.length; i++)
{
    nameValues[elementPairs[i][0]] = elementPairs[i][1];
}

// Retrieve value of a specific sub-element.
var targetElementName = "SC";
var result = nameValues[targetElementName];

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is preventing my Button's onClick() method from being effective?

Below is a snippet of my HTML layout using the sciter framework: <div id="volume_micphone_slider" style="z-index:1;"> <input id="volume_slider" class="volume_slider" type="vslider" name="p1c" max="100" value="20" buddy="p1c-buddy" /> < ...

The issue with the jQuery Mobile onclick event is that it fails to remove the ui-disabled

Ever since I delved into coding with jQuery Mobile, I've noticed a change in the function that once effortlessly removed the "ui-disabled" class. Now, all it does is display an alert message... Snippet from the HTML code: <div data-role="navbar ...

Presenting Ajax Sample Outcomes while the Form is Loading

With my Ajax form displaying water data from the US Geological Survey and a Google chart, everything is working smoothly. However, I want new users to see some sample results right away instead of an empty box upon loading the form. I am unsure of how to a ...

Experience the mesmerizing motion of a D3.js Bar Chart as it ascends from the bottom to the top. Feel free to

Here is the snippet of code I am working with. Please check the link for the output graph demonstration. [Click here to view the output graph demo][1] (The current animation in the output is from top to bottom) I want to animate the bars from Bottom to ...

Webpack automatically prepends "auto/" to script tags in the compiled HTML file

I am currently setting up an application for coding, but I am facing a problem with webpack. Every time I build the application, webpack automatically adds "auto/file.js" to the script tags instead of just "file.js". I have checked all my webpack configura ...

The useState hook is failing to update the first state in consecutive calls, only updating the second state

I've encountered an issue where running setState twice in a general function does not update the first setState. Is there a workaround for this problem? How can it be resolved? Parent const [data, setData] = useState({}); const updateData = (key, val ...

How can I integrate timer events into Protractor's control flow to track the duration of particular tasks during execution?

Let's dive into a test scenario in which a field is clicked to enter a value: it('should set value on clicking the field', function() { var field = $('.someField'); // Start timing here field.click(); this.switchToActiveE ...

Determine the area by extracting dimensions from a text string using jQuery/JavaScript

For a current project, I need to determine the square footage based on dimensions provided in a text string. The strings come from a database whenever a product is added to a list within a form. The dimensions are always height x width but can vary if meas ...

What can be used in place of Subject.prototype.hasObservers?

I have recently come across the version 4 of RxJS, and noticed that the method hasObservers on Subjects seems to have been removed. I am now faced with the challenge of migrating, as this removal is not documented on the migration guide. hasObservers: fun ...

Using a Python list as an argument in a JavaScript function

How can I pass a python list as an argument to a JS function? Every time I attempt it, I encounter the error message "unterminated string literal". I'm baffled as to what's causing this issue. Here is my python code (.py file): request.filter+= ...

What could be the reason for receiving an "undefined" response in my API ajax

I'm encountering an issue while attempting to call my API using a search term from a submit form. I keep getting an error that says "cannot read properties of undefined." I'm unsure why there is no data being returned when I send the ajax request ...

Guide on troubleshooting Node TypeScript in Visual Studio Code when the JavaScript source is stored in a separate directory

When using Visual Studio Code, I am able to debug and step through the TypeScript source code of Main.ts. This is possible as long as the JavaScript and map files are located in the same folder as the TypeScript source. This setup works well in this struc ...

`Inconsistent form variable behavior persists despite multiple ajax requests`

I'm in the process of creating a basic email submission form and I've decided to use ajax for it. The issue I'm encountering is that after successfully submitting the form once, any subsequent modifications made to the text within the form a ...

Can you explain the concept of cross referencing classes in Javascript/Typescript?

I am encountering difficulties with cross-referencing classes that are defined in the same file. // classes.ts export class A extends BaseModel implements IA { static readonly modelName = 'A'; b?: B; symbol?: string; constructor(object: ...

Change to a dark theme using React hooks in typescript

Hello, I am new to React and English is not my first language, so please excuse any mistakes. I have been trying to enable a dark mode feature on my website. Most examples I have found involve toggling between dark and light modes where you need to specify ...

Steps for extracting a specific portion of a value contained within an attribute

In my code, there are multiple hyperlinks with different values attached to an onclick function. Here is an example: <a onclick="Utils.decideOffer('', {'unlockFeature': 'cars'});">cars text</a> <a onclick="Util ...

Generating step definitions files automatically in cucumber javascript - How is it done?

Is there a way to automatically create step definition files from feature files? I came across a solution for .Net - the plugin called specflow for Visual Studio (check out the "Generating Step Definitions" section here). Is there something similar avail ...

Show notifications after being redirected to a new page

My goal is to submit a form and have the page redirected to a different URL upon submission. Currently, everything works as expected, but there is an issue with the timing of the toast message. The toast message appears immediately after the user clicks th ...

Create a drag-and-drop interface and link elements together using a custom JavaScript library

Seeking a solution or Javascript library to create a scientific modeling application, similar to flowchart software such as Visio. The ability to add elements and connect them by clicking and dragging is essential. https://i.stack.imgur.com/vSZpB.png The ...

The click event that is dynamically added is triggered multiple times

On clicking a button, I am dynamically adding a row to an HTML table. The row contains a cell with a list item (li) element which has a click event assigned to it. However, when I click on the list item, the event fires multiple times and I'm unsure w ...