I have already read the documentation but I’m still kinda confused about get_by_text
method in playwright python:
I have a small code demonstration that I try to get the selector of the text Sr. Enterprise Cloud & Snowflake Architect
then I just want to know the nature of that selector, is it a div or span or etc ..
from playwright.sync_api import sync_playwright
import os
my_path = os.getcwd()
html = open("l.html", "r", encoding="utf-8").read()
with sync_playwright() as p:
chromium_path = f'{my_path}/chromium-1076/chrome-win/chrome.exe'
browser = p.chromium.launch(executable_path=chromium_path, headless=False)
page = browser.new_page()
page.set_content(html)
element = page.get_by_text("Sr. Enterprise Cloud & Snowflake Architect", exact=True)
tag_name = element.evaluate("el => el.tagName")
print(tag_name)
browser.close()
the issue that I’m getting is this strict mode violation that I don’t get it to be honest :
playwright._impl._api_types.Error: Error: strict mode violation: get_by_text("Sr. Enterprise Cloud & Snowflake Architect", exact=True) resolved to 2 elements:
1) <span aria-hidden="true">…</span> aka get_by_text("Sr. Enterprise Cloud & Snowflake Architect").first
2) <span class="visually-hidden">…</span> aka get_by_text("Sr. Enterprise Cloud & Snowflake Architect").nth(1)
=========================== logs ===========================
waiting for get_by_text("Sr. Enterprise Cloud & Snowflake Architect", exact=True)
What I want to know is that get_by_text()
method really return a locator of the matched text or no, and that issue how to solve it if possible