Skip to content
CodeKruPro

Read the page source and search it

Automation taskEasy

Interviewers ask: "How do you check that some text or an id appears somewhere in the page HTML?" Reading the page source is one quick answer. Know its limit: it is a snapshot of the current page as text, so it cannot tell you whether something is visible or clickable. Locating elements is still the reliable way to test. Here you check that the source contains two element ids and is not empty.

Get Page Source

Get Page Source

driver.getPageSource() returns the complete HTML source of the current page. This is useful for verifying page content that might not be visible.

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Get the page source
  3. Check if it contains the text "preFilledTextField"
  4. Check if it contains the text "invisibleField"
  5. Print the results and the length of the page source

Expected output:

Contains preFilledTextField: true
Contains invisibleField: true
Source length > 0: true