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.3k stars 3.62k forks source link

[BUG] Playwright does not recognize the following xpath //*[name()='use']//@*[contains(., 'edit')] #18122

Closed NikkTod closed 1 year ago

NikkTod commented 2 years ago

I have the following html

<svg _ngcontent-kmr-c81="" width="10" height="10" viewBox="0 0 10 10" style="color: rgb(0, 82, 204);">
<use _ngcontent-kmr-c81="" xlink:href="svg#edit"></use>
</svg>

and when pasting the following xpath in the chrome devtools I receive elements returned:

//*[name()='use']//@*[contains(., 'edit')]

But when running the test, playwright is not able to find any element. I also tried with the Inspector and put the same xpath within the explore field, but nothing was returned.

Seems that the problem is with the //@*[contains(., 'edit')]

dgozman commented 2 years ago

@NikkTod Playwright selectors only work with elements, and this XPath seems to target an attribute. Let us know what you are trying to achieve, and we'll help you do it in some other way.

NikkTod commented 1 year ago

Hey @dgozman,

the whole line that was not working for me was like that:

page.locator("ta-table-row", new Page.LocatorOptions().setHasText("someText")).locator("xpath=//[name()='use']//@[contains(., 'edit')]").click();

Nevertheless by my request the devs on the project inserted some sensible class attributes for those elements, so that I can target them. We can close the ticket :)