playwright
playwright copied to clipboard
[Feature] Add locator.clear() for input fields
I would like to request a locator.clear()
functionality (similar to the one found in other frameworks) to empty the content of input fields (shouldn't be limited to input
and textarea
elements though since elements don't always follow these conventions).
Unfortunately, the workaround of using locator.fill('')
doesn't work reliably, it doesn't change the content of some input fields at all.
Unfortunately, the workaround of using locator.fill('') doesn't work reliably, it doesn't change the content of some input fields at all.
Can you submit a bug report for it instead with a repro which we can run locally?
shouldn't be limited to input and textarea elements though since elements don't always follow these conventions
how? Inserting text only works in my opinion only with input
, textarea
or [contenteditable]
elements.
Can you submit a bug report for it instead with a repro which we can run locally?
You mean add our testsuite so you can run the tests locally against our product? I don't think I'm allowed to post that publicly tbh, even more so because it touches bank account fields.
how? Inserting text only works in my opinion only with
input
,textarea
or[contenteditable]
elements.
I suggested that because I ran into the same limitation with checkboxes and selects.
According to the documentation, those locator functions only work with input
and select
respectively, as well as label
elements. And in an ideal world where everything adheres to standards, that would be suffice. But unfortunately, many checkboxes and selects and even buttons are actually a div
or other elements, which means those built-in locator functions can't be used with them (so I wrote my own wrapper functions).
I just wanted to avoid that same limitation for this feature suggestion.
You mean add our testsuite so you can run the tests locally against our product?
No, I mean creating a minimal reproducible so it does not affect any NDAs.
But unfortunately, many checkboxes and selects and even buttons are actually a div or other elements, which means those built-in locator functions can't be used with them (so I wrote my own wrapper functions).
Yeah you need to target the exact <input/>
element, then it works. This is unfortunately not something which Playwright can fix or workaround, since any UI component is different.
From what I understand you want to clear checkboxes, but for that we have locator.uncheck() and for normal text inputs we recommend fill('') which deletes internally.
Ah ok! Thanks, I'll look into that and try to provide a minimal reproducible.
But independent of my specific issue, wouldn't it be better to have a dedicated locator.clear() function in the long term?
Yeah you need to target the exact
<input/>
element
That's the problem, there is no <input/>
element. :D
Actually, I solved my issue with that input field with the good old workaround of hitting backspace in a while loop until the field is empty. The issue is most likely specific to that input field and not PW.
However, this feature request wasn't so much about my specific issue but rather about improving PW in general by adding a locator.clear()
function so people don't need to do locator.fill('')
which is less elegant. :)
However, this feature request wasn't so much about my specific issue but rather about improving PW in general by adding a locator.clear() function so people don't need to do locator.fill('') which is less elegant. :)
I agree there, fill('') is not very idiomatic!
+1
Im up for this one as well
await page.fill('[data-testid="input-name"] input', 'Slim Shady'); await page.fill('[data-testid="input-name"] input', ''); await page.fill('[data-testid="input-name"] input', 'Dr Dre');
This doesnt sit right.
Hi @dgozman and everyone,
The clear feature does not work on a numeric input. I am using 1.36.1 playwright version. Only this code worked
let keyboardKey = os.platform().toString() === 'darwin'?"Meta+A": "Control+A"; await page.keyboard.press(keyboardKey); await page.keyboard.press("Backspace");
Not sure if i should create a new issue for this.
Thanks
Please file a new issue for it, thanks!