开发者

How to get text of single input tag

I am using a input tag as follows:

<input type="text" autocomplete="off" class="x-form-field
x-form-text" size="20" name="someField" id="ext-gen1203"
aria-invalid="false" role="textbox"
aria-describedby="textfield-1117-errorEl" aria-required="true"
style="width: 463px;">

I want to retrieve the value in the text field, I could not use selenium.getText() command as there is no text shown in DOM, also I could not u开发者_如何学编程se selenium.getValue() as tag has no value attribute.

How to get the text from the input field?


I know this is old, but I have the answer in case someone stumbles upon this:

In Java, just call getAttribute("value") In C#, it's GetAttribute("value")

So for example, if I needed the text value from an input element, in C# it would look something like this:

driver.FindElement(By.XPath("//table[contains(@class, 'role-listing')]/tbody/tr/td/input")).GetAttribute("value")


maybe you can try this

store | id="ext-gen1203" | varNameYouWant

the value inside the text box will not store in the variable "varNameYouWant", to call back the value you may use ${varNameYouWant}

Hope this help.


If you want to copy a value that in the text input, hidden or something element.

<input id="from_element" value="this is from value" />
<input id="to_element" value="" />

You need two steps,

1.Get the value "from_element" and store to variable "myVariable". You can decide variable name by yourself.

storeValue | id=from_element | myVariable

2.Paste the stored value into "to_element" by using below command.

type | id=to_element | ${myVariable}

hope it will help others also. :)


I suppose that if the input field is not empty, the tag will have the value attribute. You should check if the value attribute exists and only then get its value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜