Validating placeholder text using Selenium Webdriver

I have a text box that displays placeholder text when the text box is out of focus. When the focus shifts to this text box (by placing the cursor in the text box), the placeholder text disappears and the cursor appears in the text box. I am trying to automate a script that confirms this behavior. Has anyone ever tried to automate a similar scenario? We appreciate any suggestions. Thanks

+5
source share
2 answers

You can get placeholder text using the method getAttributefor webdriver.

HTML:

<input id="<ur id>" class="<ur class name>" type="password" lang="en" maxlength="30" placeholder="Enter Password" data-label="passwordPlaceholder" tabindex="5">

Java Code:

String password=driver.findElement(By.cssSelector("ur css path")).getAttribute("placeholder");
+4
source

. - placeholder . Ruby :

element = @driver.find_element(*<locator string>*)
expected_placeholder_text = element.attribute('placeholder') 

, , . element.attribute

element['placeholder'] 

( ).

+1

All Articles