6

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." + "xxxxx@spamgourmet.com"; 

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:

driver.findElement(By.xpath(".//*[@id='reset-password-wrap']/form/div[1]/input")).sendKeys(emailRandom);

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?

5

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 Dec 20 '16 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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