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.93k stars 3.67k forks source link

IsVisible/innerText is not working. #21479

Closed JeevanHB closed 1 year ago

JeevanHB commented 1 year ago

locator.isVisible(xpath=//workspace[@ng-model="workspace.name"]/a)— ../../../workspaces/page/workspacesPage.js:112 111 | // var text = getPage().locator(this.locator); 112 | console.log("Text is "+ await getPage().locator(this.workspaceNameInListingLoc).isVisible()) | ^ 113 | return await getPage().locator(this.workspaceNameInListingLoc).innerText();

Please guide us what is the syntax we r missing in above code, Isvisble/innerText is not working in our script. image

image

nnson0310 commented 1 year ago

It seems your locator does violate strict mode of Playwright. Strict mode means your locator should and must resolve to only one web element. In stack trace, it resolves to 15 elements.

mxschmitt commented 1 year ago

As per above, a strict mode violation is if a locator resolves to multiple elements. To solve this you can do e.g.

to target a specific element. You can also call .locator('more specific') on your existing locator to make it more specific.

JeevanHB commented 1 year ago

Thanks