I want to getText() using By.id or By.cssSelector.
I managed to solve my problem by doing getAttribute("value"), but I don\'t understand why getText() doesn
Simple answer - it's designed this way. getText()
parses the content of the tag (i.e. its innerText), which is obviously empty for inputs.
You may use this if you want to search for a given text on a WebElement. Pass it directly or through a string:
String textoToSearch = "Text inside Webelement";
driver.findElement(By.id("someID).getText().contains("textToSearch");
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#getText()
getText() delivers the innerText of a WebElement.
Your input field does not have any inner Text. The text is found inside your value-attribute, hence accessing it via getAttribute("value") is the correct way to do it.
Java
ele.getAttribute("innerHTML");
This could get the text already in the background and not displayed on the page yet.