solved issue: cannot write to an input field successfully /duplicate input
tldr; if your fill command duplicates the input, use pressSequentially
Hi All, I was trying to send input into an apps form using the fill operator. I was getting duplicate entries ie. page.getbyRole('textbox).fill("peter") resulted in peterpeter. I spent about 30 minutes trying to debug it (figure out what I was doing wrong). I could not resolve it, but found a good workaround.
My solution was a workaround of using pressSequentially. I just wanted to share it as a workaround and to thank the playwright team for not having just 1 way of inputting text. Totally saved me.
This thread is trying to answer question "How to fix the issue of the fill command duplicating the input in an app's form?"
Actually pressSequentially is discouraged (that's the reason for renaming it from type to pressSequentially), and the Playwright dev team suggests using fill wherever possible. https://playwright.dev/docs/release-notes#deprecations https://playwright.dev/docs/api/class-locator#locator-press-sequentially
A common reason why fill or even pressSequentially might not work as expected is when the app logic is interfering with the typing.
For example if the app is not initialized fully yet, and changes focus, or initializes fields with default values while Playwright was typing.
In most cases you can rely on Playwright's auto-waiting to interact with the page only when it becomes ready to handle input: https://playwright.dev/docs/actionability
But many apps are somewhat sloppy and don't care to disable controls while they are still initializing or busy with something else, so then Playwright's actionability checks pass and Playwright continues typing and clicking while the page is not really ready to handle input.
In such cases you have to explicitly wait for some indication that the page is ready. For example waiting for the last expected network response.
await page.waitForResponse(/someresponse/);
Or waiting for a field to get focused.
await page.locator('password:focus').waitFor()
It depends on the app what will work for you. The best solution of course is to fix the app.
I'm seeing the same issue now. I don't see how this is solved. The issue started for me with v1.40 It is only in debug mode. The status of the field has nothing to do with it because in debug I can step and wait indefinitely before doing the fill. I pause right before the fill, wait for the page to be stable and ready and it still fils double the text.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].