Auto waits and page.waits not working v0.1.3

Auto waits are not working locating, clicking or for any other action I tried. Also page.wait… not working. Non of them. My test works when I enter sleep() . If I don’t enter sleep(). I get this error: TypeError: Cannot read property ‘click’ of undefined or null

Hi MCengiz,

Welcome to the community.

Could you please share the website you’re testing on and your script? So we can hopefully figure out the problems.


Here is my script. Unfortunately I cannot share the website I am testing. I see same problem reported in the examples.

export default function main(data) {
  const browser = launcher.launch('chromium', { headless: false });
  const context = browser.newContext();
  let page = context.newPage();

  // Goto front page, find login link and click it
  page.goto(auth_url, { waitUntil: 'networkidle' });


  page.waitForNavigation(); //this wait works here 

  //go to messages 
    page.goto(messages_url, { waitUntil: 'networkidle' });
page.waitForNavigation(); //but does't works here
page.waitForSelector(locators.txtMessage);//does't works here
page.waitForLoadState('networkidle');//does't works here

page.waitForTimeout(8000) // works
sleep(5) // works

  //send message


Thanks for sharing the examples.

Since you see the same problem in our example, is it possible for you to validate the problem using the fillform example and share the script with me? So hopefully, we can find the problem quickly.

Please tell me if I’m asking for too much. Thank you!

Your example fill form worked for me without sleep.

Actually, it doesn’t work. It worked because of slowMo: '500ms' // slow down by 500ms
When I remove it it fails on typing admin

1 Like

I created my own find method to locate elements an it works for now.

find(page,locator,waitTime) {
    waitTime = waitTime || 10000;
    let flag=false;
    let iter=0;
    let element;
      try {
        element = page.$(locator);
      } catch (error) {} 
    return element;
1 Like

Thanks for more information. It helps. We’ll look into this issue and hopefully come up with a fix.

Hi @MCengiz,

your issue is difficult to reproduce since we don’t have access to your site, and it hasn’t come up when testing other sites.

That said, there have been several fixes since you reported this, which might’ve improved things for you. Could you test again using the latest v0.2.0?

Make sure to run the test with the XK6_BROWSER_LOG=trace environment variable, so that we can see debug information. E.g. XK6_BROWSER_LOG=trace ./xk6-browser run -q script.js 2>&1 | tee script.log. And then upload the script.log to this thread, or send it to one of us via PM, if it contains sensitive data.

Some notes and questions:

  • We fixed the fillform.js example, but the fix wasn’t in the xk6-browser code but in the example itself. Previously it was using waitForLoadState() incorrectly, when it should’ve been using waitForNavigation(). So you’ll see that now it doesn’t need sleep() nor slowMo.

  • Is your site a SPA or does it have a lot of dynamic asset loading and navigation? In these cases it’s difficult to know when the page has actually finished loading (i.e. reached networkidle state), since it might continuously load assets in the background. In most cases this will have to involve some type of timeout, but we suggest using waitForSelector() instead of waitForNavigation(), which should be more reliable.

  • I think your script has some issues, which I address here, along with an approach for determining networkidle on SPAs, which hasn’t been implemented yet.

If you can change your script according to the above and share that run log with us, it could help us get to the bottom of this. Thanks!