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.
WebDriverManager.chromedriver().setup(); ChromeDriver driver = new ChromeDriver(); driver.get("https://www.programsbuzz.com/user/login"); driver.manage().window().maximize(); driver.findElement(By.className("fa-search")).click(); WebElement searchBox = driver.findElement(By.id("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"); else System.out.println("Correct placeText NOT is shown ......PASSED"); driver.close();
- 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.