-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
sidebar_label: AutofillData | ||
--- | ||
|
||
# AutofillData interface | ||
|
||
#### Signature: | ||
|
||
```typescript | ||
export interface AutofillData | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | Default | | ||
| ---------- | --------- | --------------------------------------------------------------------------------------- | ----------- | ------- | | ||
| creditCard | | { number: string; name: string; expiryMonth: string; expiryYear: string; cvc: string; } | | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
sidebar_label: ElementHandle.autofill | ||
--- | ||
|
||
# ElementHandle.autofill() method | ||
|
||
If the element is a form input, you can use [ElementHandle.autofill()](./puppeteer.elementhandle.autofill.md) to test if the form is compatible with the browser's autofill implementation. Throws an error if the form cannot be autofilled. | ||
|
||
#### Signature: | ||
|
||
```typescript | ||
class ElementHandle { | ||
autofill(data: AutofillData): Promise<void>; | ||
} | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --------- | ------------------------------------------- | ----------- | | ||
| data | [AutofillData](./puppeteer.autofilldata.md) | | | ||
|
||
**Returns:** | ||
|
||
Promise<void> | ||
|
||
## Remarks | ||
|
||
Currently, Puppeteer supports auto-filling credit card information only and in Chrome in the new headless and headful modes only. | ||
|
||
```ts | ||
// 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', | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
</head> | ||
|
||
<body> | ||
<form id="testform" method="post"> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<label for="name">Name on Card</label> | ||
</td> | ||
<td> | ||
<input size="40" id="name" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<label for="number">Card Number</label> | ||
</td> | ||
<td> | ||
<input size="40" id="number" name="card_number" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<label>Expiration Date</label> | ||
</td> | ||
<td> | ||
<input size="2" id="expiration_month" name="ccmonth"> <input size="4" id="expiration_year" | ||
name="ccyear" /> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright 2023 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import expect from 'expect'; | ||
|
||
import {getTestState, setupTestBrowserHooks} from './mocha-utils.js'; | ||
|
||
describe('Autofill', function () { | ||
setupTestBrowserHooks(); | ||
describe('ElementHandle.autofill', () => { | ||
it('should fill out a credit card', async () => { | ||
const {page, server} = await getTestState(); | ||
await page.goto(server.PREFIX + '/credit-card.html'); | ||
const name = await page.waitForSelector('#name'); | ||
await name!.autofill({ | ||
creditCard: { | ||
number: '4444444444444444', | ||
name: 'John Smith', | ||
expiryMonth: '01', | ||
expiryYear: '2030', | ||
cvc: '123', | ||
}, | ||
}); | ||
expect( | ||
await page.evaluate(() => { | ||
const result = []; | ||
for (const el of document.querySelectorAll('input')) { | ||
result.push(el.value); | ||
} | ||
return result.join(','); | ||
}) | ||
).toBe('John Smith,4444444444444444,01,2030,Submit'); | ||
}); | ||
}); | ||
}); |