node.js – Puppeteer – Returning null content to my scrape

I am doing a web scrape on the google page, using node.js and puppeteer, so the user enter the ticker of the stock, I concatenate to the google search URL and then I scrape the variation of that stock at the moment. But sometimes it works and sometimes I recieve the error: Error: Evaluation failed: TypeError: Cannot read property ‘textContent’ of null.

I’ve already tried using the waitForSelector function and then got a time out, also, using the waitUntil: "domcontentloaded" didn’t work as well. What do I do?

Here’s the sample of my code that is not working: (There are 3 possible elements, if the variation is up, down or zero, that’s why there are 2 conditionals)

const browser = await puppeteer.launch({ args: ("--no-sandbox") });
const page = await browser.newPage();
const ticker = fundParser(fund);
const url = "https://www.google.com/search?q=" + ticker.ticker; //Ticker value could be rztr11, arct11 or rzak11
await page.goto(url,{ waitUntil: "networkidle2"});
console.log("Visiting " + url);

 // scrapes variation text. If positive or zero, the first scrape will be null, so there's a conditional for changing its value to the correct one
var variation = await page.$(
    "#knowledge-finance-wholepage__entity-summary > div > g-card-section > div > g-card-section > div.wGt0Bc > div:nth-child(1) > span.WlRRw.IsqQVc.fw-price-dn > span:nth-child(1)"
);
if (variation == null) {
  variation = await page.$(
    "#knowledge-finance-wholepage__entity-summary > div > g-card-section > div > g-card-section > div.wGt0Bc > div:nth-child(1) > span.WlRRw.IsqQVc.fw-price-up > span:nth-child(1)"
  );
  if (variation == null) {
    variation = await page.$(
    "#knowledge-finance-wholepage__entity-summary > div > g-card-section > div > g-card-section > div.wGt0Bc > div:nth-child(1) > span.WlRRw.IsqQVc.fw-price-nc > span:nth-child(1)"
    );
}}
console.log("Extracting fund variation");
const variationText = await page.evaluate(
  (variation1) => variation1.textContent,
  variation
);
console.log("Extracted:" + variationText);