Get Text Content and Inner Text
Playwright provides multiple ways to read text:
locator.textContent()— all text (including hidden), likeelement.textContentin JSlocator.innerText()— only visible text, likeelement.innerTextin JSlocator.innerHTML()— the inner HTML markup
On the Text Messages page:
#italicTexthas italic text#hiddenTexthas text that is hidden (visibility: hidden). Its text has a leading space in the HTML, so call.trim()on it
Task:
- Navigate to
https://testkru.com/Elements/TextMessages - Get the text content of
#italicText - Get the text content of
#hiddenText(textContent works even on hidden elements) - Check if
#hiddenTextis visible
Expected output:
Italic: Italic Text Hidden text: A Hidden Text Hidden visible: false
TestKru