ElementHandle.autofill() 方法
¥ElementHandle.autofill() method
如果该元素是表单输入,则可以使用 ElementHandle.autofill() 来测试表单是否与浏览器的自动填充实现兼容。如果无法自动填写表单,则会引发错误。
¥If the element is a form input, you can use ElementHandle.autofill() to test if the form is compatible with the browser's autofill implementation. Throws an error if the form cannot be autofilled.
签名
¥Signature
class ElementHandle {
abstract autofill(data: AutofillData): Promise<void>;
}
参数
¥Parameters
范围 | 类型 | 描述 |
---|---|---|
data |
Returns:
Promise<void>
备注
¥Remarks
目前,Puppeteer 仅支持自动填充信用卡信息,并且在 Chrome 中仅支持新的 headless 和 headful 模式。
¥Currently, Puppeteer supports auto-filling credit card information only and in Chrome in the new headless and headful modes only.
// Select an input on the credit card form.
const name = await page.waitForSelector('form #name');
// Trigger autofill with the desired data.
await name.autofill({
creditCard: {
number: '4444444444444444',
name: 'John Smith',
expiryMonth: '01',
expiryYear: '2030',
cvc: '123',
},
});