Having a slight issue that I solved on my own but I would like an explanation as to why .getText does not work.

So I had it create a random email

private static  String randomEmail() {
    return UUID.randomUUID().toString() + ".20." + "[email protected]"; 

I then wanted it to copy the email I just made with this code.

final String emailRandom = driver.findElement(By.xpath(".//*[@id='step5']/input")).getText

This however did not actually copy anything, everytime I tried to make it use the code via:


Nothing would come up or be pasted.

I switched the .getText to .getAttribute("value"); and it works flawlessly.

Question: Why does .getText not work but .getAttribute work?

1 Answer 1


With all the regular elements, you would use getText() to get the "text" of an element, but input elements (W3C input form control spec) are special - the "text" is kept under the value attribute.

Related threads:

  • Thanks, did not realize the input would not be covered by getText, your answer makes sense. cheers.
    – Christian
    Commented Dec 20, 2016 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.