问题
so in my code i submit a form , wait for navigation and submit a second form ... here is the tricky part ... before the second from submit some data will be loaded in the from with ajax
i want to wait for those ajax call the be done and then submit the second form
here is a simplified version of my code
await Promise.all([
page.click('#form1_submit'),
page.waitForNavigation(),
])
if (!await page.$("#form2_element"))
throw new Error(' ELEMENT MISSING 2 ');
await page.$eval('#form2_element', (el, data) => el.value = data.value , data);
await Promise.all([
page.click('#form2_submit'),
page.waitForNavigation(),
])
after this
await Promise.all([
page.click('#form1_submit'),
page.waitForNavigation(),
])
how can i say wait for ajax calls ? i tried this
await Promise.all([
page.click('#form1_submit'),
page.waitForNavigation({ waitUntil: "networkidle0" }),
])
but it didnt work and for submited before ajax call is done
回答1:
If you want to wait for data to be displayed after an AJAX call is made, I'll point you towards my answer on this very topic from another thread:
how to handle elements that load after ajax request in puppeteer
Hopefully this helps!
来源:https://stackoverflow.com/questions/53283834/puppeteer-wait-for-ajax-call-after-navigation