木偶:如何提交表单?

使用木偶 ,你怎么能以编程方式提交表单? 到目前为止,我已经能够使用page.click('.input[type="submit"]')如果表单实际上包含提交input。 但是,对于不包含提交input的表单,关注表单文本input元素并使用page.press('Enter')似乎实际上不会导致表单提交:

 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 into the search bar await page.focus('.js-search-field'); await page.type('puppeteer'); // Submit form await page.press('Enter'); // Wait for search results page to load await page.waitForNavigation({waitUntil: 'load'}); console.log('FOUND!', page.url()); // Extract the results from the 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(); })(); 

Solutions Collecting From Web of "木偶:如何提交表单?"