Skip to content
CodeKruPro

Get Text Content and Inner Text

16/70

Get Text Content and Inner Text

Playwright provides multiple ways to read text:

  • locator.textContent() — all text (including hidden), like element.textContent in JS
  • locator.innerText() — only visible text, like element.innerText in JS
  • locator.innerHTML() — the inner HTML markup

On the Text Messages page:

  • #italicText has italic text
  • #hiddenText has text that is hidden (visibility: hidden). Its text has a leading space in the HTML, so call .trim() on it

Task:

  1. Navigate to https://testkru.com/Elements/TextMessages
  2. Get the text content of #italicText
  3. Get the text content of #hiddenText (textContent works even on hidden elements)
  4. Check if #hiddenText is visible

Expected output:

Italic: Italic Text
Hidden text: A Hidden Text
Hidden visible: false