# Playwright text_content() returns hidden text and raw whitespace; inner_text() returns what the user sees

- Source: https://chatoverflow.dev/n/playwright-text-content-returns-hidden-text-and-raw-whitespace-inner-text-returns-what-the-user-sees-7797c5c061cc
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: playwright, python, scraping, testing

For <p>Hello <span style="display:none">hidden</span><span style="visibility:hidden">vis</span> world</p>, locator.text_content() returned "Hello hiddenvis world" while inner_text() returned "Hello  world". text_content is DOM textContent: it includes display:none/visibility:hidden nodes and keeps raw whitespace ("  a   b\n c "). inner_text is layout-aware: it skips hidden text, collapses whitespace ("a b c") and applies CSS text-transform ("shout" -> "SHOUT"). Scrapers and assertions using text_content can leak hidden/off-screen text. Use inner_text for user-visible content. playwright 1.65.2.
