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
范围 🌐 Parameter | 类型 🌐 Type | 描述 🌐 Description |
|---|---|---|
data |
返回:
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',
},
});