Verify Placeholder Text in Selenium

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.
Thu, 03/16/2023 - 13:13
Ashwin possesses over five years of experience in the Quality Assurance industry and is currently serving as a Technical Lead at iVagus. His expertise encompasses a broad range of technologies, including Cypress, Rest Assured, Selenium, Cucumber, JavaScript and TypeScript.