javascript - Puppeteer: How to submit a form? -
using puppeteer, how programmatically submit form? far i've been able using page.click('.input[type="submit"]')
if form includes submit input. forms don't include submit input, focusing on form text input element , using page.press('enter')
doesn't seem cause form submit:
const puppeteer = require('puppeteer'); (async() => { const browser = await puppeteer.launch(); const page = await browser.newpage(); await page.goto('https://stackoverflow.com/', {waituntil: 'load'}); console.log(page.url()); // type our query search bar await page.focus('.js-search-field'); await page.type('puppeteer'); // submit form await page.press('enter'); // wait search results page load await page.waitfornavigation({waituntil: 'load'}); console.log('found!', page.url()); // extract results page const links = await page.evaluate(() => { const anchors = array.from(document.queryselectorall('.result-link a')); return anchors.map(anchor => anchor.textcontent); }); console.log(links.join('\n')); browser.close(); })();
try this
const form = await page.$('form-selector'); await form.evaluate(form => form.submit());
Comments
Post a Comment