Verify Placeholder Text in Playwright Java

Profile picture for user arilio666

In this article, we will see how to verify placeholder text in playwright java.

  • Placeholder text, or dummy text, is a temporary text used as a visual aid for designing and laying out content. 
  • It is commonly used in the website and graphic design, and it typically appears in form fields, search bars, and other user input areas where text can be entered.
  • This is a simple placeholder text in the search bar of the programsbuzz site.
  • Using the get attribute method, let us verify the text within the search bar, which is the placeholder text.

        Locator searchBar = page.locator("#edit-keys");
        String placeText = searchBar.getAttribute("placeholder");

        if (placeText.contains("Enter the terms you wish to search for")) {


        } else {
            System.out.println("FAIL! No such texts");
  • First, we fetched the search bar, and then using the same locator, we got the attribute placeholder of the search bar.
  • We verified the text within it using a simple if else statement.