Error: waiting for element state: element is not attached to the DOM

I am trying to automate login into a Microsoft account as part of a more complex test. However k6 throws an error:

ERRO[0007] Uncaught (in promise) clicking on “[type=submit]”: waiting for element state: element is not attached to the DOM executor=shared-iterations scenario=ui

Below is the script that I am using. When I copy the script body to Playwright it works fine.

I have already tried waiting for different load states. The only thing that seems to work is adding a sleep(1) after each await, but that is not a viable option.


export default async function () {
  const context = await browser.newContext();
  const page = await context.newPage();

  try {
    const username = __ENV["USERNAME"];
    const password = __ENV["PASSWORD"];

    await Promise.all([
      page.waitForLoadState("networkidle"),
      page.goto("https://login.microsoft.com", {
        waitUntil: "domcontentloaded",
      }),
    ]);
    await page.fill("input[name=loginfmt]", username);
    await Promise.all([
      page.waitForLoadState("networkidle"),
      page.click("[type=submit]"),
    ]);
    await page.locator('[name="passwd"]').fill(password);
    await Promise.all([
      page.waitForLoadState("networkidle"),
      page.locator("[type=submit]").click(),
    ]);
    await Promise.all([
      page.waitForLoadState("networkidle"),
      page.locator("[type=submit]").click(),
    ]);
  } finally {
    await page.close();
    await context.close();
  }
}

1 Like

I had the same issue. upgrading to 1.2.o seems to hve fixed this for me.

``
npx npm-check-updates -u
npm install
``