Using puppeteer , how could you programmatically submit the form? So far, I could do this using page.click('.input[type="submit"]')if the form actually includes an input file. But for forms that do not include input, focusing on the form's text input element and using page.press('Enter')does not seem to result in the form being submitted:
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());
await page.focus('.js-search-field');
await page.type('puppeteer');
await page.press('Enter');
await page.waitForNavigation({waitUntil: 'load'});
console.log('FOUND!', page.url());
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();
})();
source
share