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

fix(locator): locator(locator) method uses internal:chain instead of >> #24235

Merged
merged 1 commit into from
Jul 14, 2023

Conversation

dgozman
Copy link
Contributor

@dgozman dgozman commented Jul 14, 2023

Usually, we can just chain two locators with >> to implement Locator.locator(locator). However, this does not play nicely with more advanced inner locators like or and and:

const child = page.locator('input').or(page.locator('button'));
page.locator('parent').locator(child);

One would expect the above to locate "input or button" inside a "parent". However, currently it locates "input inside a parent" or "button", because it's translated to parent >> input >> internal:or="button".

To fix this, we have to wrap inner locator into internal:chain and query it separately from the parent.

Fixes #23724.

… instead of `>>`

Usually, we can just chain two locators with `>>` to implement `Locator.locator()`.
However, this does not play nicely with more advanced inner locators like `or` and `and`:

```ts
const child = page.locator('input').or(page.locator('button'));
page.locator('parent').locator(child);
```

One could expect the above to locate "input or button" inside a "parent".
However, currently it locates "input inside a parent" or "button".

To fix this, we have to wrap inner locator into `internal:chain` and
query it separately from the parent.
@dgozman dgozman merged commit 97d55e2 into microsoft:main Jul 14, 2023
25 of 27 checks passed
Germandrummer92 pushed a commit to OctoMind-dev/playwright that referenced this pull request Oct 27, 2023
… of `>>` (microsoft#24235)

Usually, we can just chain two locators with `>>` to implement
`Locator.locator(locator)`. However, this does not play nicely with more
advanced inner locators like `or` and `and`:

```ts
const child = page.locator('input').or(page.locator('button'));
page.locator('parent').locator(child);
```

One would expect the above to locate "input or button" inside a
"parent". However, currently it locates "input inside a parent" or
"button", because it's translated to `parent >> input >>
internal:or="button"`.

To fix this, we have to wrap inner locator into `internal:chain` and
query it separately from the parent.

Fixes microsoft#23724.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] and and or locator methods incorrectly match elements outside of parent locator
2 participants