-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: Make fill_form more appealing when filling forms with checkboxes #1971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,11 +204,33 @@ async function fillFormElement( | |
| if (aXNode && aXNode.role === 'combobox' && hasOptionChildren(aXNode)) { | ||
| await selectOption(handle, aXNode, value); | ||
| } else { | ||
| // Increase timeout for longer input values. | ||
| const timeoutPerChar = 10; // ms | ||
| const fillTimeout = | ||
| page.pptrPage.getDefaultTimeout() + value.length * timeoutPerChar; | ||
| await handle.asLocator().setTimeout(fillTimeout).fill(value); | ||
| const isToggle = await handle.evaluate(el => { | ||
| if (el instanceof HTMLInputElement) { | ||
| return el.type === 'checkbox' || el.type === 'radio'; | ||
| } | ||
| const role = el.getAttribute('role'); | ||
| return role === 'checkbox' || role === 'radio' || role === 'switch'; | ||
| }); | ||
|
|
||
| if (isToggle) { | ||
| const shouldBeChecked = value.toLowerCase() === 'true'; | ||
| const isChecked = await handle.evaluate(el => { | ||
| if (el instanceof HTMLInputElement) { | ||
| return el.checked; | ||
| } | ||
| return el.getAttribute('aria-checked') === 'true'; | ||
| }); | ||
|
|
||
| if (isChecked !== shouldBeChecked) { | ||
| await handle.asLocator().click(); | ||
| } | ||
| } else { | ||
| // Increase timeout for longer input values. | ||
| const timeoutPerChar = 10; // ms | ||
| const fillTimeout = | ||
| page.pptrPage.getDefaultTimeout() + value.length * timeoutPerChar; | ||
| await handle.asLocator().setTimeout(fillTimeout).fill(value); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| handleActionError(error, uid); | ||
|
|
@@ -313,7 +335,7 @@ export const drag = definePageTool({ | |
|
|
||
| export const fillForm = definePageTool({ | ||
| name: 'fill_form', | ||
| description: `Fill out multiple form elements at once`, | ||
| description: `Fill out multiple form elements at once. To set checkboxes fill them with 'true'`, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a test to tests/tools/input.test.ts that tests checkboxes and verify that it actually accepts a string
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I misread some eval results thinking it already works this way. Pushed an update to make fill and fill_form handle those, together with tests. |
||
| annotations: { | ||
| category: ToolCategory.INPUT, | ||
| readOnlyHint: false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fixed in puppeteer's fill()