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();
Author by
Fazy
Updated on April 27, 2021Comments
-
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 over 11 yearsThanks bob, it works as expected. Why using Firebug the entered text is not getting updated in the value attribute ?
-
TK Tang over 4 yearsJust to be clear, it has be to getAttribute("value"), lower case. Not "Value". Which is what i got wrong.
-
mlhDev over 4 yearsI do not see that function, do you have documentation on it?