I'm trying to use puppeteer to save data on website from a excel.Fisrt click the add button on the page,It will navigate to the add form, then extract data from excel file.And type the data in each input field, click save.It will redirect to the list page.After that click add button again.
Here's part of my code:
readExcel().then(async data => {
//Read data from excel line by line
for (let row = 1; row < 5; row++) {
let from = 'A' + row;
let to = 'B' + row;
//get Value1
let fromValue = data[from].v;
//get Value2
let toValue = data[to].v;
let addButton = await page.$('.action-links a');
await addButton.click();
await page.waitForNavigation({ waitUntil: 'domcontentloaded'
}).then(async () => {
let fromUrl = await page.$('#edit-source');
let toUrl = await page.$('#edit-redirect');
let save = await page.$('#edit-submit');
await fromUrl.type(fromValue);
await toUrl.type(toValue);
await save.click();
});
}
It only save first line of data.Reported error: UnhandledPromiseRejectionWarning: Error: Execution context was destroyed, most likely because of a navigation. Anyone can help me?