Prasanta Biswas Prasanta Biswas - 1 year ago 112
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.

Answer Source

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...:)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download