Puppeteer: How to submit a form?

前端 未结 2 1211
离开以前
离开以前 2020-12-28 12:24

Using puppeteer, how could you programmatically submit a form? So far I\'ve been able to do this using page.click(\'.input[type=\"submit\"]\') if the form actua

相关标签:
2条回答
  • 2020-12-28 12:52

    Try this

    const form = await page.$('form-selector');
    await form.evaluate(form => form.submit());
    

    For v0.11.0 and laters:

    await page.$eval('form-selector', form => form.submit());
    
    0 讨论(0)
  • 2020-12-28 13:11

    If you are attempting to fill out and submit a login form, you can use the following:

    await page.goto('https://www.example.com/login');
    
    await page.type('#username', 'username');
    await page.type('#password', 'password');
    
    await page.click('#submit');
    
    await page.waitForNavigation();
    
    console.log('New Page URL:', page.url());
    
    0 讨论(0)
提交回复
热议问题