Verify Text is not Present in Playwright Python

Profile picture for user arilio666

Use the page to check if a specific text is missing from a web page using Playwright and Python.content() method to extract the page's content and then check if the text is missing.

Example:

from playwright.sync_api import sync_playwright, expect
with sync_playwright() as p:
  browser = p.chromium.launch(headless=False)
  page = browser.new_page()
  text_to_verify = "Spam VIrus@@!@#^&%^&*"
  page.goto('https://www.programsbuzz.com/user/login')
  content = page.content()
  if text_to_verify not in content:
  	print(f"The text '{text_to_verify}' is not present on the page.")
  else:
  	print(f"The text '{text_to_verify}' is present on the page.")       

Here we used the content() method, which returns the entire DOM of a page, and then using that and if else statement, we checked to see if the text_to_verify content is not on the page.