Hello there! I am trying to fill a text input, using the locator.fill() method, but without emptying its content first, I only want to add more text after the existing content. It seems the function automatically clears the content first, and I don't see any option to prevent this.
Is there any way to achieve this behaviour? Thank you for your help!
This thread is trying to answer question "No question was provided in the thread."
use the new presssequentially api: https://playwright.dev/docs/api/class-locator#locator-press-sequentially
Unfortunately it seems to behave the same. The only way I managed to make it work is by combining it with locator.press()
So basically doing this:
const inputField = page.getByRole('textbox');
await inputField.press('ArrowRight'); // I guess this cancels the "selectAll" applied on the content?
await inputField.pressSequentially(' change');
Any chance an option like fill(' change', { clear: false })
would be possible to add? I feel like it would be a simpler api ๐
Yes, it does work, it's basically the option I show above. The downside is that you have to use pressSequentially
instead of fill
, which is less performant. And the docs say to use pressSequentially
only for "special keyboard handling", which is not the case here.
I tried to open a feature request, but it was not really received as I hoped... https://github.com/microsoft/playwright/issues/27484 ๐คทโโ๏ธ
This is not blocking me, I was just hoping for a more efficient approach to do this ๐
@tphillips8117 The use case would be to just extend a field's existing value, instead of replacing it completely. For example, I might want to take a screenshot of a form, that has a big textarea. And I want to see how it looks like when the textarea has a couple more lines. Instead of having to retype everything, I would prefer to just add the necessary content.
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].