I
I
Ivan Ivanov2019-12-12 00:52:38
Node.js
Ivan Ivanov, 2019-12-12 00:52:38

How to shorten entry on nodejs, puppeteer?

I use node.js, puppeteer. There is such a code

let clicked_editorial_button = await page.evaluate(() => {
    if(document.querySelector("button.section-editorial-button") !== null)
    {
      document.querySelector('button.section-editorial-button').click();
      return true;
    }
    else
    {
      return false;
    }
  });

Is it possible to do all this through a function or through a method. Ideally, you could write like this:
let clicked_editorial_button = await page.evaluate(() => {
    return document.click_or_return_false("button.section-editorial-button");
  });

Is it possible to somehow write click_or_return_false for document to work in any await page.evaluate?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question