Prasanta Biswas Prasanta Biswas - 8 months ago 55
Java Question

How to get entered text from a textbox having no value attribute in selenium

My element looks like this:

<input name="ctl00$PlaceHolderPopUp$ReviewName"
type="text" maxlength="255" id="PlaceHolderPopUp_ReviewName"
class="giInput_two inputHeight_two"

Retrieving code:

String value=driver.findElement(By.xpath("//*@id='PlaceHolderPopUp_ReviewName']")).getText().trim();

I want to enter some text in it and retrieve the text before saving. I used
method but it is not retrieving any text.


If target element is input element, you should try as below :-

WebElement el=driver.findElement(By.xpath("//*@id='PlaceHolderPopUp_ReviewName']"));
String value = el.getAttribute("value");

Note :- input element always contains entered text in their attribute property value. It does matter that their attribute value present or not. Hope it will help you...:)