microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.5k stars 3.64k forks source link

[Bug]: Playwright locator from generateLocator refers to the wrong html element #32903

Open fabianboth opened 3 weeks ago

fabianboth commented 3 weeks ago

Version

1.47.2

Steps to reproduce

On https://www.redbus.in/, click the calendar dropdown.

Then try to generate a locator with playwright.generateLocator for any of the date fields.

Expected behavior

Getting a playwright locator, that could click the respective date field when using locator.click(). Similar to clicking with the mouse on the date entry, this should select the correct date in the date picker.

Actual behavior

The locator refers to a button which opened the calendar drop-down. All dates refer to this button, and clicking does not select a date.

Additional context

This is the mentioned calendar dropdown: image

If e.g. 10th of Oct is selected as element, the playwright locator resolves to the button element instead image

The element where the locator points to image

Environment

System:
    OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11950H @ 2.60GHz
    Memory: 15.38 GB / 31.05 GB
    Container: Yes
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
    pnpm: 9.11.0 - ~/.nvm/versions/node/v20.15.1/bin/pnpm
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
  npmPackages:
    @playwright/test: 1.47.2 => 1.47.2 
    playwright-core: 1.47.2 => 1.47.2
Skn0tt commented 3 weeks ago

Can reproduce, but unsure if this is correct. @dgozman could you take a look?

dgozman commented 2 weeks ago

@fabianboth This is because the whole date-picker table is inside a <div role=button> that opens it. Playwright assumes that when you'd like to click on an element inside a button, you'd actually like to click on the button.

I think the web site is doing something strange, but Playwright is also limiting the ability to generate a recording. I am not yet sure what would be the best solution. Maybe generating multiple locators could help.