Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental/browser: strict mode violation, multiple elements returned for selector query #1344

Open
luka-nikolic opened this issue May 23, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@luka-nikolic
Copy link

Brief summary

When multiple elements match selector and I want to execute click() on locator I get error: Uncaught (in promise) clicking on "[data-action="add-to-cart"][aria-label="In den Warenkorb"][data-quantity-input="#quantity"]": strict mode violation, multiple elements returned for selector query

Code example:

    const addToCartButton = page.locator('[data-action="add-to-cart"][aria-label="In den Warenkorb"]');
    await addToCartButton.click();

k6 version

v0.51.0

OS

Windows 10

Docker version and image (if applicable)

No response

Steps to reproduce the problem

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
  thresholds: {
    checks: ["rate==1.0"]
  }
}

export default async function () {
  const page = browser.newPage({extraHTTPHeaders: HEADERS});

  try {
    await page.goto(BASE_URL);
    const addToCartButton = page.locator('[data-action="add-to-cart"][aria-label="In den Warenkorb"]');
    await addToCartButton.click();
  } finally {
    page.close();
  }
}

There are multiple elements on page that match selector [data-action="add-to-cart"][aria-label="In den Warenkorb"].
It fails when i execute click() method

Expected behaviour

.locator() should return only the first element that matches the selector (similar to how HTML DOM Document querySelector() works).

Actual behaviour

.locator() return multiple elements.

@luka-nikolic luka-nikolic added the bug Something isn't working label May 23, 2024
@joanlopez joanlopez assigned ankur22 and unassigned joanlopez May 23, 2024
@joanlopez joanlopez transferred this issue from grafana/k6 May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants