Missing semicolon in Playwright [closed]

1 week ago 16
ARTICLE AD BOX

Your click selector is the main problem.
You define it like this:
this.product = "//div[normalize-space()='${productName}']";

Since the class doesn’t receive productNam, that string never gets interpolated. Playwright literally sees "${productName}", so the locator won’t match anything.

Just build the selector inside the loop when you actually have the value:

async addToCart(productName) { const items = await this.page.$$(this.productList); for (const item of items) { const text = await item.textContent(); if (text?.includes(productName)) { await this.page.locator(`//div[normalize-space()='${productName}']`).click(); break; } } }

I hope this will be work for you.

user31923518's user avatar

New contributor

user31923518 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Read Entire Article