puppeteer : wait for ajax call after navigation [duplicate]

只谈情不闲聊 提交于 2021-01-29 06:30:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!