How to get value from a placeholder using xpath

selenium-webdriver, xpath

Solution

String s=driver.findElement(By.xpath("//input[@placeholder='Gender']")).getAttribute("placeholder"); 
System.out.println(s);

To get an attribute for a filed, you can use the .getAttribute() method.

Problem

All of the elements are dynamic. I can see only Placeholder which is unique from the following html:- ``` <input id="ext-gen1617" type="text" size="20" class="x-form-field x-form-text x-form-focus" autocomplete="off" aria-invalid="false" placeholder="Gender" data-errorqtip="" role="textbox" aria-describedby="combobox-1166-errorEl" aria-required="true" style="width: 78px;" /> ``` I need to get the value displayed in ``` placeholder="Gender". ``` I tried using ``` //input[@placeholder='Gender'] ``` But my webdriver script failed to identify it. Can anyone please help me out with possible solution to it?

Original source