let's see this one now! I have one code placing a string into input type then clicking on submit. I need to read one excel to get the string then place on that input. The problem is I'm getting error because I can't use await.page inside the excel function.
So that's my code:
const puppeteer = require('puppeteer');
const delay = require ("delay");
var Excel = require('exceljs');
var wb = new Excel.Workbook();
var path = require('path');
var filePath = path.resolve(__dirname,'sample.xlsx');
wb.xlsx.readFile(filePath).then(function(){
var sh = wb.getWorksheet("Sheet1");
for (i = 1; i <= sh.rowCount; i++) {
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://www.melissa.com/user/signin.aspx?src=https://www.melissa.com/v2/lookups/emailcheck/email/');
//authentication
await page.waitFor('input[name="ctl00$ContentPlaceHolder1$Signin1$txtEmail"]');
await page.$eval('input[name="ctl00$ContentPlaceHolder1$Signin1$txtEmail"]', elu => elu.value = '4n1kl4t0r@gmail.com');
await page.waitFor('input[name="ctl00$ContentPlaceHolder1$Signin1$txtPassword"]');
await page.$eval('input[name="ctl00$ContentPlaceHolder1$Signin1$txtPassword"]', elp => elp.value = 'v3r1fy>>2020');
await page.click('input[type="submit"]');
//search
var result_cell = sh.getRow(i).getCell(2).value;
await page.waitFor('input[name="email"]');
await page.$eval('input[name="email"]', el_e => el_e.value = result_cell);
await page.click('input[type="submit"]');
//await page.waitForNavigation();
await delay(3000);
//scrapping score
const result_score = await page.evaluate(() => {
let score = document.querySelector('#tableInfo50 > tbody > tr:nth-child(3) > td.text-left.bold-text').innerText
return {
score
}
})
console.log(result_score)
browser.close()
})()
}
});