Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
How to get data from json file to js using puppeteer

How can i get data such as username and password from json file?

const { errors } = require('puppeteer');
const puppeteer = require('puppeteer-extra');

(async () => {
    const browser = await puppeteer.launch({
      headless: false,
      ignoreHTTPSErrors: true,
      webpage: true,
      slowMo: 3,
      executablePath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
    });

    const page = await browser.newPage();
    await installMouseHelper(page); // Makes mouse visible
    await page.setDefaultNavigationTimeout(0);
    await page.evaluate(() => { debugger; });
    await page.goto('https://nike.com/my/login');

    await page.waitFor(500);
    const login = '[data-componentname="emailAddress"]';
    loginButton = await page.waitForSelector(login),
    await loginButton.click(),
    await loginButton.type("test@gmail.com");

    await page.waitFor(500);
    const loginPsw = '[data-componentname="password"]';
    loginPswButton = await page.waitForSelector(loginPsw),
    await loginPswButton.click(),
    await loginPswButton.type("Qwert12345.");

    await page.waitFor(500);
    const signInBtn = '[class="nike-unite-submit-button loginSubmit nike-unite-component"]';
    signInBtnButton = await page.waitForSelector(signInBtn),
    await signInBtnButton.click();

})();
{
"nikeSNKRS": {
    "accounts": [
        {
            "note": "",
            "accounts": [
                {
                    "user": "test@gmail.com",
                    "password": "Qwert12345.",
                    "access_token": "",
                    "refresh_token": "",
                    "expires_in": "",
                    "token_type": "",
                    "country": "",
                    "phone": "",
                    "expires": "???",
                    "proxy": ""
                }
            ]
        }
    ]
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you do not want to mess up your existing code with call-back nesting, create an async method to read in the file containing your data:

const fs = require("fs");

const getData = (file) => {
  return new Promise((resolve, reject) => { 
    fs.readFile(file, (err, data) => {
      if (err) return reject(err);
      try {
        const json = JSON.parse(data);
        resolve(json);
      } catch (E) {
        reject(E);
      }
    }
  }
}

Then if your data is in ./data.json, add to/modify your code at the appropriate places:

const json = await getData("./data.json");
//...
const user = json.nikeSNKRS.accounts[0].accounts[0].user;
await loginButton.type(user);
// ...
const password = json.nikeSNKRS.accounts[0].accounts[0].password
await loginPswButton.type(password);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!