How to get entered text from a textbox in Selenium

95,905

The getText() method is for retrieving a text node between element tags for example:

<p>Something</p>

getText() will return "Something"

In a textbox typed text goes into the value attribute so you can try something like:

findElement(By.id("someid")).getAttribute("value");

ComboBox is a bit different. But if you're using the Select object you can use the method:

Select selectItem = new Select(findElement(By.id("someid")));
selectItem.getFirstSelectedOption().getText();
Share:
95,905
Fazy
Author by

Fazy

Updated on April 27, 2021

Comments

  • Fazy
    Fazy about 3 years

    I enter a value in TextBox or a Combobox, and would like to retrieve the value I have just entered. I see that Selenium Weblement method getText() doesn't retrieve the value, it seems the entered text doesn't get pushed into DOM.

    Any solutions?

  • Fazy
    Fazy over 11 years
    Thanks bob, it works as expected. Why using Firebug the entered text is not getting updated in the value attribute ?
  • TK Tang
    TK Tang over 4 years
    Just to be clear, it has be to getAttribute("value"), lower case. Not "Value". Which is what i got wrong.
  • mlhDev
    mlhDev over 4 years
    I do not see that function, do you have documentation on it?