Context:
- Playwright Version: 1.27 (reproduce from 1.24)
- Operating System: Mac
- Node.js version: 16.14.2
- Browser: All
Code Snippet
async selectAssetByName(asset: string) {
const strictEqualAsset = new RegExp(^${asset}$, "g");
const assetLabelText = this.page.locator("data-testid=rightText", { hasText: strictEqualAsset });
await assetLabelText.click();
}
await this.selectAssetByName("Apple");
error:
locator.click: Error: strict mode violation: "data-testid=rightText >> internal:has="text=/^Apple$/g"" resolved to 4 elements:
1) <span class="rightText--2qLZ" data-testid="rightText">…</span> aka playwright.$("li:has-text("Add to Watchlist AAPL:NASDApple") >> internal:attr=[data-testid="rightText"]")
2) <span class="rightText--2qLZ" data-testid="rightText">…</span> aka playwright.$("text=Apple Hospitality")
3) <span class="rightText--2qLZ" data-testid="rightText">…</span> aka playwright.$("text=Apple International")
4) <span class="rightText--2qLZ" data-testid="rightText">…</span> aka playwright.$("text=Appleton Apollo Tubes")
**Unable to get element by text with regex**
Context:
Code Snippet
async selectAssetByName(asset: string) {
const strictEqualAsset = new RegExp(
^${asset}$, "g");const assetLabelText = this.page.locator("data-testid=rightText", { hasText: strictEqualAsset });
await assetLabelText.click();
}
await this.selectAssetByName("Apple");