What is the best way to compare a collection of items found online with those stored on your device?

Despite numerous tutorials, I am still struggling to grasp this concept. To practice, I am currently working on where I am attempting to retrieve a list of elements and compare it to another list to ensure accuracy. I plan to do the same after sorting from Z to A, as well as by price. However, being fairly new to this, I am finding it quite challenging. So far, I have only managed to obtain the list and reverse it (?)

const array1 = $$('.inventory_item_name').forEach(element => {
            console.log(element.getText())
        });
const array2 = $$('.inventory_item_name').reverse().forEach(element => {
            console.log(element.getText())
        });

When attempting to compare these lists using ===, they turn out to be true :/ I am experimenting with this in VScode -Js - webdriverIO - Mocha

Answer №1

Recently stumbled upon an informative tutorial on Udemy

const itemNameElements = $$('.inventory_item_name'); //retrieves the item names
const originalItemNames = itemNameElements.map(item => item.getText()); //maps and converts item names to text
console.log(originalItemNames) //displays the item names in an array
const copiedItemNames = originalItemNames.slice() //creates a copy of item names without altering the original array
const sortedItems = copiedItemNames.reverse() //organizes the copied list to match the website's order
console.log(sortedItems) //logs it for personal reference
expectChai(originalItemNames).to.eql(sortedItems) //compares both arrays of text

Adding .reverse() caused the test to fail in this scenario. When omitting .slice, the test was passing regardless of values and order. Instead of using .sort(), I will make adjustments if sorting is done on the page itself. The same principle can be applied to prices.

An alternative method would have been to simply verify the first and last item names during sorting, but opting for that route seemed too elementary.

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

The submission feature for the textarea in Javascript is not functioning properly

As someone who is new to frontend development, I am currently facing a challenge with debugging JavaScript code that involves making changes to the content of a textarea. Despite my efforts to debug using the browser console, I have yet to identify why it ...

Attempting to maintain the main navigation highlighted while browsing through the secondary navigation

I am facing a small issue that seems like it should be an easy fix, but I can't seem to figure it out. While working on my site, I'm having trouble keeping the parent navigation highlighted when scrolling through the sub-menu. If you hover over ...

Tips for eliminating repetitive code in JavaScript

I have a jQuery function that deals with elements containing a prefix 'receive' in their class or ID names. Now, I need to duplicate this function for elements with the prefix 'send'. Currently, it looks like this: function onSelectAddr ...

Combining the elements within a nested array

When I retrieve an array, it often looks like this: array (size=376) 0 => array (size=3) 'source' => int 0 'target' => int 47 'officers' => array (size=1) 0 => string ...

Transform JavaScript array into PHP array

Seeking assistance! Currently, I am in the process of extracting content by class name using JavaScript and storing it into an array. My goal is to display this array as a drop-down list using PHP on a .php page. Here's what I have accomplished so fa ...

Establishing the ISO date time to the beginning of the day

When working with a Date retrieved from a Mongo query in ISO format, the goal is to compare it with today's date. To accomplish this, a new Date is created and its time is set to zero: var today = new Date(); today.setHours(0,0,0,0); //Sat Jan 20 201 ...

How can we use an Array containing nested Objects in TypeScript?

Wondering about the best way to achieve this: let x = [{}]; in TypeScript. I've searched high and low for a definitive answer to this query. My assumption is that it can be done using the Array object: let x : Array<Object> = new Array<Obj ...

Error 404 in NodeJS: Page Not Found

I recently started working with NodeJS to develop an ecommerce application. I have a ready-made design and all the front-end components built using AngularJS code. Everything seems to work fine - when clicking on any menu, the page content changes along wi ...

The deployment is currently being carried out

Here is the javascript code snippet I am working with: $scope.fav_details = function(id1,id2,bio) { document.getElementById(id2).style.display="none"; document.getElementById(id1).style.display="block"; $scope.getLegislatorDeta ...

The form submission button fails to function when the onsubmit function returns false

When submitting, I check two fields. If one of the two fields is checked, then I return true; otherwise, I return false. The issue I'm facing is that even when I check one of the checkboxes, the submit button does not seem to work (I use console.log() ...

Why are the $refs always empty or undefined within Vue components?

I am completely new to working with Vue and I've been attempting to utilize $refs to retrieve some elements within the DOM from a sibling component. My objective is very basic, as I just need to obtain their heights, but I haven't had much succes ...

Generate Random Quotes - Each new quote should be different from the previous one

As I tackle the FreeCodeCamp 'Random Quote Machine' front end library project using React JSX, everything seemed to be running smoothly except for one major issue - the same quote was often generated two or three times in a row. Obviously, this i ...

ERROR: Module 'jquery' not found in path 'C:....' when using Gulp and Browserify

Encountering an error: Error: Module 'jquery' not found in path 'F:...\newstyle\assets\lib\helper\html\img\js' at C:\Users...\AppData\Roaming\npm\node_modules&bs ...

resolved after a new promise returned nothing (console.log will output undefined)

Here is my Promise Function that iterates through each blob in Azure BlobStorage and reads each blob. The console.log(download) displays the values as JSON. However, when trying to close the new Promise function, I want the resolve function to return the ...

Tips for broadcasting a router event

Currently, I am working with 2 modules - one being the sidenav module where I can select menus and the other is the content module which contains a router-outlet. I am looking for the best way to display components in the content module based on menu selec ...

Unable to Submit Form in JSP Page

I have encountered an issue with a JSP page that contains a form which I am submitting using JavaScript. When the page has a smaller number of items, between 10-50, the submission works perfectly fine. However, when there are around 500 items or more on t ...

Tips for sorting through an array by odd or even index values

Is there a way to filter out array entries based on odd or even index numbers? Array ( [0] => string1 [1] => string2 [2] => string3 [3] => string4 ) I am looking to remove the entries with indexes [0] and [2]. For example, if I ...

Issue with ngModel being undefined after data has finished loading in Ionic 3

As a newcomer to Angular 4, I've been struggling to find a solution for a seemingly simple issue related to an Ionic app. Whenever a user logs in, the entire user object is saved to localStorage. Despite trying various plugins, I settled on a straight ...

Fade In/Out Scroll Effect

As the user scrolls down the page, I have a slider that smoothly slides from right to left. What I'm trying to achieve is for the slider to fade out when the last slide is no longer in view during downward scrolling, and fade back in as the last slid ...

Compare and contrast JSON files that are constantly changing using JavaScript

I have reviewed the various inquiries on comparing JSON objects and feel confident in my ability to implement a comparison. However, my question pertains to dynamically loading source .json files into JSON objects for comparison. The scope of my project h ...