I'm trying to access linkArray after I use it as a function. Right now I'm getting a Reference Error saying my linkArray is not defined. I've also tried to used let and var and I had the same error. How can I use that array in a different scope without getting that error? I checked if linkArray is correctly filled and it is. In javascript.
const linkArray = await page.evaluate(() => {
let setLinkArray = [];
let elements = document.getElementsByClassName('setStoreLink');
for (var element of elements){
let setLinkID = element.id;
setLinkArray.push(setLinkID);
}
return setLinkArray;
});
var doSomething = await page.evaluate(() => {
return linkArray;
});
Hi,
Please check what page.evaluate function is returning. You are
assigning value to the linkArray which is returned by page.evaluate
function.
In your case page.evaluate function not returning what your passing function returns.
Let's take example where I can reproduce your similar problem,
// let take example page is object having evaluate
function
// evaluate method receives function normally we call it as
callback function.
let page = {
evaluate: function(callback){
// evaluate execute the callback
callback();
}
}
// lets call page.evaluate with some dummy function which returns
object with success key and value
let result = page.evaluate(()=>{
return {success: true};
});
// get the result from page.evaluate
let doSomething = page.evaluate(()=>{
return result;
})
// print the result
console.log(doSomething);
For the output is: undefined
Reason :
page.evaluate executes the callback function not returning any
value. So result will set as undefined. And also on do something my
passing function is returning result but page.evaluate is not
returning it. So again do something is set to undefined.
To rectify this I'm adding return statement in page.evaluate function which will return result that is returned by callback(passing function)
Check this:
// let take example page is object having evaluate
function
// evaluate method receives function normally we call it as
callback function.
let page = {
evaluate: function(callback){
// evaluate execute the callback and returns result
return
callback();
}
}
// lets call page.evaluate with some dummy function which returns
object with success key and value
let result = page.evaluate(()=>{
return { success: true};
});
// get the result from page.evaluate
let doSomething = page.evaluate(()=>{
return result;
})
// print the result
console.log(doSomething);
From above code check the underlined code.
Now output is : { success: true }
In your check the what page.evaluate is doing and returning.
Images:
1. Without return statement:

2. With return statement:

Hope you got what you want, if you have any doubts please comment below (don't forget add what page.evaluate is doing and returning). Cheers..:))
I'm trying to access linkArray after I use it as a function. Right now I'm getting...
I am working on my java but I keep getting this one wrong.
Method Name: arrayContains Access modifier: Private Parameters: 1 integer named number Return type: boolean Purpose: This method returns a true or a false indicating if the number is present in an array or not. In order for this method to work, there must be an array already declared. Therefore, in the CLASS BLOCK, declare an array as follows: static int[] listof Numbers = {1, 2, 3, 4,...
I'm trying to plot GPX data using the geoshow function in MATLAB. Ideally, I want to be able to select the GPX file from a file explorer, which is why I used the uigetfile function. What I get from my current code is the full plot of data (lats/longs) with the correct axes. However, I'm having a tough time getting this data overlayed onto a map. I've tried using the webmap functions but this is not exactly what my team...
Data Structures and Algorithms C++: I'm having a hard time getting my main.cpp part of the source code (shown below) to output the following: Inserting elements to array list: The list contains 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Deleting elements: The list contains: 2 4 6 8 10 12 14 16 18 20 22 24 this is a programming problem in...
Can someone please help, third time I'm asking. I need a basic javascript with no push or splice command. Please don't post a picture of the code,because my vision is poor and I won't be able to see it. Also, I need breakdown of what's in HTMLand what' s in javascript. All requirements are below. Thanks for your help. This is a 2 part assignment, but both parts can be completed in one program. Also, please follow ALL Required Programming...
Hi!, having trouble with this one, In this class we use visual studio, C++ language -------------------------------------------------------------- Exercise #10 Pointers - Complete the missing 5 portions of part1 (2 additions) and part2 (3 additions) Part 1 - Using Pointers int largeArray (const int [], int); int largePointer(const int * , int); void fillArray (int * , int howMany); void printArray (const char *,ostream &, const int *, int howMany); const int low = 50; const int high = 90; void main()...
IMPLEMENT AN IMMUTABLE SINGLY LINKED LIST IN JAVASCRIPT ------------------------------------------------------------------------------------------------------------------------- So I am trying to implement a singly linked list that given the below function will pass the bottom four tests when ran. Please help me generate the singly linked list that will work and pass the tests. I will only use this as a reference so please add comments to explain what you are doing so I can understand and write this myself. I think a join method may need...
I have to a C++ program I need help with. Can you break it into the two steps provided below. Suppose MAX_SIZE is a global constant int variable that has been declared and initialized to an appropriate positive value. 1. int maxValue(const array<int, MAX_SIZE>&, int); is the prototype for a function that returns the value of the largest element in the array parameter. The array may be only partially filled. The int parameter indicates how many items are actually in...
What's wrong with my code? : I'm trying to use recursive functions to display and count all the even numbers of an array. However, I can't seem get the program output the number of even integers . Here's the output I want: Here are the 5 even numbers: // Luckily, however, my code does output all the even numbers. But, I also want the program to tell me how may even integers there are. 2 8 14 18 22 MY...
My code is not doing what I want it to do and I can't seem to figure out why it's not working. I commented some of the code to give some context to what I'm trying to do. Can someone check to see where my code is off. I'm assuming that I didn't use the counters properly or I'm using the pointers incorrectly. I can only use pointers to do this by the way. Code: #include <iostream> using namespace std;...
I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...