如何获得单输入标签的文本
问题描述:
我使用的是输入标签如下:如何获得单输入标签的文本
<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;">
我要检索的文本字段中的值,我无法使用selenium.getText()命令有DOM中没有显示任何文本,也无法使用selenium.getValue()作为标记没有值属性。
如何从输入字段中获取文本?
答
也许你可以试试这个
商店| id =“ext-gen1203”| varNameYouWant
文本框将不会在变量“varNameYouWant”里面存储的值,再打你可以使用$ {} varNameYouWant
希望这有助于价值。
答
我想如果输入字段不是空的,标签将具有值属性。你应该检查值属性是否存在,然后才能得到它的值。
答
我知道这是旧的,但我有,以防有人绊倒在这个答案:
在Java中,只需拨打getAttribute("value")
在C#中,这是GetAttribute("value")
因此,举例来说,如果我需要的从输入元素文本值,在C#中它会是这个样子:
driver.FindElement(By.XPath("//table[contains(@class, 'role-listing')]/tbody/tr/td/input")).GetAttribute("value")
答
如果要复制,在文本输入,隐藏的值什么元素。
<input id="from_element" value="this is from value" />
<input id="to_element" value="" />
你需要两个步骤,
1.Get值 “from_element”,并存储到变量 “MYVARIABLE”。你可以自己决定变量名称。
storeValue | id=from_element | myVariable
2.使用下面的命令将存储值粘贴到“to_element”中。
type | id=to_element | ${myVariable}
希望它也能帮助别人。 :)
'商店'没有为我工作,'storeValue'没有。 –