puppeteer form submit: evaluate is not a function

red*_*hka 5 puppeteer

the form exists in the page and i am sure.

const form = await page.$('#my-form');
await form.evaluate(form => form.submit());
Run Code Online (Sandbox Code Playgroud)

I get this error:

TypeError: form.evaluate is not a function
Run Code Online (Sandbox Code Playgroud)

Md.*_*her 1

编辑 2019:正如 Kyle 提到的,最新的 puppeteer在 elementHandle 上有 .evaluate 方法。毕竟已经过去两年了。

const tweetHandle = await page.$('.tweet .retweets');
expect(await tweetHandle.evaluate(node => node.innerText)).toBe('10');
Run Code Online (Sandbox Code Playgroud)

你可以试试这个方法

await page.evaluate(() => {
 const element = document.querySelector("#my-form")
 element.submit()
});
Run Code Online (Sandbox Code Playgroud)

ElementHandle不具有.evaluate函数属性。检查文档