Verify Placeholder Text in Selenium

Profile picture for user arilio666

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

  • 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.
        ChromeDriver driver = new ChromeDriver();




        WebElement searchBox = driver.findElement("edit-keys"));

        String placeText = searchBox.getAttribute("placeholder");

        if (placeText.equals("Enter the terms you wish to search for"))
            System.out.println("Correct placeText is shown ......PASSED");
            System.out.println("Correct placeText NOT is shown ......PASSED");

  • First, we fetched the search bar, and then using the same locator, we got the attribute placeholder of the search bar.
  • With that, we verified the text within it.