How to wait for JavaScript to finish in playwright

I am testing UI with Playwright and JavaScript. My code find an input element that can sometimes be a drop down, sometimes a text and sometimes a date. To handle this I enter value with 2 steps. First I fill the text and then click on tab key to invoke the JavaScript that formats the value in the element.

await page.fill("#myID", inputText); 
await page.keyboard.press('Tab');  // this line trigger the JS

// continue to the next element 

The problem, it is not waiting for JavaScript to finish. How can I wait for JS to finish before the code continue.

52 thoughts on “How to wait for JavaScript to finish in playwright”

  1. I’m curious to find out what blog platform you’re utilizing?
    I’m experiencing some minor security problems with my latest website
    and I would like to find something more risk-free.
    Do you have any suggestions?

    Reply
  2. Hey there! Quick question that’s entirely off topic.

    Do you know how to make your site mobile friendly? My weblog looks weird when viewing from
    my iphone4. I’m trying to find a theme or plugin that might be able
    to correct this problem. If you have any recommendations, please share.
    Appreciate it!

    Reply
  3. Greetings from Los angeles! I’m bored at work so I decided to check out your blog on my iphone during lunch break.

    I enjoy the information you present here and can’t wait to
    take a look when I get home. I’m surprised at how fast your
    blog loaded on my mobile .. I’m not even using
    WIFI, just 3G .. Anyways, excellent blog!

    Reply
  4. This is really interesting, You’re a very skilled blogger.
    I have joined your rss feed and look forward to seeking more of your fantastic post.
    Also, I have shared your web site in my social networks!

    Reply

Leave a Comment