使用 Selenium WebDriver 获取禁用输入的值 [英] Get the value of disabled input using Selenium WebDriver
本文介绍了使用 Selenium WebDriver 获取禁用输入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取已禁用 (disabled="disabled"
) 字段的值,但它返回一个空字符串.>
我已经尝试过:.Text
、GetAttribute("value")
,但到目前为止这些都不起作用.
解决方案
如果你这样标记 -
你的代码应该是 -
WebElement.getAttribute(禁用")
或
WebElement.getAttribute("id")
确保您的代码正确.
对于这个标签 -
获取value属性-
String value = driver.findElement(By.id("j_idt93:j_idt93")).getAttribute("value");
值必须是 Pārtraukts
如果这不起作用,您可能必须使用 JavaScript 执行器 -
String value = (String)((JavascriptExecutor) driver).executeScript(JavaScript 在此处查询返回值", ");
您的查询应该是 -
return document.getElementById("j_idt93:j_idt93").getAttribute("value");
I'm trying to get value of a disabled (disabled="disabled"
) <input>
field, but it returns an empty string.
I have tried: .Text
, GetAttribute("value")
, but none of this works so far.
解决方案
If you tag it like this -
<input disabled="true" id='data'>
Your code should be -
WebElement.getAttribute("disabled")
or
WebElement.getAttribute("id")
Make sure your code is correct.
For this tag -
<input id="j_idt93:j_idt93" type="text" disabled="disabled" maxlength="2000" value="Pārtraukts">
To get the value attribute -
String value = driver.findElement(By.id("j_idt93:j_idt93")).getAttribute("value");
value must be Pārtraukts
If this does not work, you may have to use the JavaScript executor -
String value = (String)((JavascriptExecutor) driver).executeScript("JavaScript query in here to return the value", "");
Your query should be -
return document.getElementById("j_idt93:j_idt93").getAttribute("value");
这篇关于使用 Selenium WebDriver 获取禁用输入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文