ElementHandle.autofill() 方法
如果元素是表单输入项,你可以使用 ElementHandle.autofill() 来测试表单是否与浏览器的自动填充实现兼容。如果表单无法自动填充,则抛出错误。
签名
class ElementHandle {
abstract autofill(data: AutofillData): Promise<void>;
}
参数
|
参数 |
类型 |
说明 |
|---|---|---|
|
data |
返回值:
Promise<void>
备注
目前,Puppeteer 仅支持自动填充信用卡信息,并且仅支持 Chrome 的新无头模式和有头模式。
// 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',
},
});