I'd like to know how to get the values from a bi-dimensional array in Selenium.
I have a file called resources.js, where I create the arrays and access it in Selenium, here is the array:
This array must have 4 columns and n numbers of lines.
How do I store the values of the 4 columns in variables? (it would be good to do it in a WHILE loop, to store/show the values from all rows if possible)
This is what I've tried and failed miserably:
This seems like more of a JavaScript question than a Selenium question. The way to access multi-dimensional arrays in JS is like: Test[array_index][item_in_array_index].
So if you were trying to get the value 'name1', it would be Test[0][0].
Related
im new to js, have two question about how to parse a csv, i have a simple csv with two column, column1:'user', column2:'amount'
how can i get one array with all the 'user' column value and one
array with all the 'amount' column value?
And can i loop trough the rows and use index to get the
value of the two column? something like csv['amount'][0] or csv[0][1] or something like this?
ty.
First, declare 2 arrays, one for user, one for amount.
And then read this post to know how to read a file line by line.
After that, read this post to know how to split a string with a comma separator.
Finally, use the array.push() method to push the data into an array.
This question already has answers here:
MongoDB: count the number of items in an array
(3 answers)
Query for documents where array size is greater than 1
(14 answers)
Closed 5 years ago.
Im writing a simple query to return user content/posts.
I also need to show the number of comments each post has.
My document structure looks like this
posts {
content: string,
comments: [array of object ids]
...
}
I know how to get the size of the comments array using aggregate function.
I also know that i could add a "commentsNr" property and increment it using post save hooks.
And...i know i can execute the query....return the posts array, and use the post.comments.length property, but i don't want to return the entire comments array just to count it.
All my queries are very simple, and i don't want to make them any more complicated than necessary.
So, im looking for a way to return the length of the comments array as a new field, i.e use projection or something like that.
Is there a way to use simple find query to get the length of the document array, without returning the array itself ?
I see your intention but I'm sorry... It is not possible to use $size in a projection outside the aggregation framework. Go for the aggregation option, though, without feeling bad about it! This framework is so amazing that you will want to use it at some point anyway...
Situation: I have an array called "array1" with some strings in it.
For example, when I type array1.length , then the program gives me the amount of strings in the array back. What do I have to do to get "6" back (The amount of letters in the array name "array1")
maybe you could youst wrap the arrays with numbers in one array and the other ones in another array and just use the wrapper array you need.
without seeing your code this is the best solution i can give you
Below, I have attached an image with some console output. What I would like to do is, grab all the numbered nodes (so, 0 and 1, but there could be more or less), and put them into an array (like [0, 1]).
Is this possible?
Use .toArray().
var listOfNodes = $list.toArray();
EDIT: As was pointed out by SterlingArcher, there's a better option in ES6 in the form of Array.from.
var listOfNodes = Array.from($list);
You can use a simple for-loop
To go through these arrays just don't use forEach, with that you will go through every property but you want the numbers only
Jquery uses a combination of arrays and associative array (objects in Javascript)
So it has auto incremented keys and words as keys
There are fixed three columns in it. The rows are added dynamically and may go up-to few thousands also.
I should also be able to iterate through the array and filter Id & Values based on level.
Is this possible ? How?
Arrays of Arrays are easy.
[[1, 234,'Apple'],[2,23,'Sunday'], ....]
To add something to the array, push use push. To iterate forEach. filter is not yet in the JS standard, but here is a polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
I suggest for your problem to look at not building an Array of Arrays, but model each row as a JS object:
{level: 1, id: 234, value: 'Apple'}
that way you can write more semantic code like
myObjectList.filter(function(obj){ return obj.level > 1 })
rather than using array indexes everywhere.
In general if you ant get an idea what you can do with JS built-ins like Array, check the JS reference at the Mozilla Developer Network. Its pretty good and has lots of examples for each Array function like forEach or find, or filter.