[Feature] elementHandle.$ query in whole page instead of the given element
According https://playwright.dev/docs/api/class-elementhandle#elementhandleselector, i should be able to subquery for a given element .
It appears to query the whole page instead of the given element.
Ex: https://the-internet.herokuapp.com/add_remove_elements/
- Click button (//div[@class="example"]/button)
- Retrieve elementHandle(//div[@class="elements"])
- Subquery this one using elementHandle.$('//button')
- Click this element
=>
Add elementbutton is clicked instead ofDelete
I tried to reproduce it with the following example which seems to work as expected, once I move it inside the div, I get two results and otherwise 1 result: https://try.playwright.tech/?s=evnej1h
Could you provide us a full example?
it seems to be appear only when i using xpath selectors:
// @ts-check
const playwright = require("playwright");
(async () => {
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.setContent(`
<span class="find-me">1</span>
<div id="a1">
<span class="find-me">2</span>
</div>`)
const baseElement = await page.$(`//*[@id="a1"]`);
let element = await baseElement.$(`//*[@class="find-me"]`);
console.log(await element.innerText())
await browser.close();
})();
This isn't a bug formally, because instead of .// that starts search from the current node, you explicitly requested // that resets search to the root of the document. But I can see how this can be confusing. We should probably treat // as .// in this method.