There’re several ways of finding an element that matches the text exactly:
Using page.get_by_text():
page.get_by_text("Welcome, John", exact=True))
Using page.locator():
page.locator('text="Some text"')
# note: the nested double-quotes indicate exact match
XPath alternative:
page.locator('//a/span[text()="Exact Text"]')