Alpha
Alpha

Reputation: 14026

How to get text from input tag?

I've a case where I've to get the text from input tag which is something like -

<input id="AB_WIN_1" class="text real" type="text" ds="0" style="top:0px; left:167px; width:140px; height:21px;"/>

And the text in that input tag is some text say Hello

But when I use getText, it returns nothing.

Is there anyway I can get text from input tag?

Upvotes: 1

Views: 5296

Answers (2)

Mrunal Gosar
Mrunal Gosar

Reputation: 4683

you can use any of the below:

1. element.getAttribute("value")
2. element.getAttribute("innerHTML")
3. element.getAttribute("innerText")
4. element.getText()
5. ((JavascriptExecutor)driver)execute.script("return arguments[0].value",element)

Let me know if this does not helps.

Upvotes: 6

Ali Sheikhpour
Ali Sheikhpour

Reputation: 11045

use element.getAttribute("value"). getText can not extract input value.

Upvotes: 1

Related Questions