0

It does not matter if I try type or fill on the element using the playwright inspector console, it shows the error as below:

playwright.$("//app-date-picker[@formcontrolname='myDate']//input").fill('a2');

VM51594:1 Uncaught TypeError: playwright.$(...).fill is not a function
at <anonymous>:1:72

However, if I run the type method from my Playwright Java code, it runs without error:

Locator birthDateField = page.locator("//app-date-picker[@formcontrolname='myDate']//input");
birthDateField.fill("");

What can cause the difference and why it is not working with the fill method in playwright inspector? The selector is correct, only the fill method is problematic somehow.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
L. Measy
  • 1
  • 1
  • 1
    What is `playwright.$("//app-date-picker[@formcontrolname='myDate']//input")`? Try logging it to find out. – Solomon Ucko Mar 31 '23 at 21:33
  • Thank you for the reply. It is an angular input element. – L. Measy Mar 31 '23 at 21:38
  • 1
    [`.$` is deprecated](https://playwright.dev/docs/api/class-page#deprecated) and doesn't wait for anything. This isn't a complete, runnable [mcve] so it's hard to tell how you're actually using this, but usually you have to `const eh = await page.$(...)` to get a handle, then you can call methods on it. Without the `await` you're just working with a raw promise, and promises don't have a `.fill()` method. – ggorlen Mar 31 '23 at 21:55
  • Whoops, I didn't realize you're using Java, not JS. I think the Java API is synchronous, so that invalidates my answer and part of my comment. The problem might be that `$` doesn't wait for the element while `locator` does, but we'd have to see the site to say for sure. It's odd that you say `$` finds an input--doesn't seem to match the error. Is there a reason this is tagged [tag:javascript]? Java and JS are totally unrelated languages. I'll pull off that tag unless there's good reason to keep it. – ggorlen Mar 31 '23 at 22:17

0 Answers0