How to write an element locator of which the text value could be parameterized in Pytest Playwright.
Eg: We can do it like this in Selenium,
- initially define a string:
String product_code = form[@data-id='PRODUCT_CODE']
- and then updating the variable value by:
By.xpath(lbl.replace("PRODUCT_CODE", product)
How can we achieve the same in pytest playwright for an element locator with get_by_text
?
I have tried the following and didn't work.
test_fav_list = page.query_selector(f'[name="{self.element_name}"]')
element_name = name
test_fav_list.click()
element = self.page.query_selector(f'[name="{name}"]')
if element:
element.click()