javascript - Selenium (Java): Retrieve value from disabled input text field

标签 javascript java html css selenium

我正在尝试使用 Java 中的 Selenium 从输入字段中检索值。这是相关的 HTML 代码:

<input class="form-control input-sm " id="NameInputID" type="text" maxlength="16" name="NameInput" value="TheValueWanted" readonly="">

我试过:

driver.findElement(By.id("NameInputID")).getText();

driver.findElement(By.id("NameInputID")).getAttribute("value");

它们都没有返回值(空白文本)。我该如何处理?

谢谢!

最佳答案

你可以通过 JavascriptExecutor 试试:

Thread.sleep(3) // add a pause to wait until value of the element will be rendered
JavascriptExecutor je = (JavascriptExecutor) driver;
String script = "return document.getElementById('NameInputID').getAttribute('value');");
String value = je.executeScript(script);

关于javascript - Selenium (Java): Retrieve value from disabled input text field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51382479/

相关文章:

javascript - zippyshare.com 直接下载链接

javascript - 如何处理多个用户的localStorage?

javascript - 下拉菜单仅单击选定的行

javascript - 列表中的按钮,如何使其 ''编辑''好行?

android - PhoneGap 应用中 &lt;input type ="number"> 的 Android ICS 键盘行为不一致

javascript - 在 jQuery 中创建水平滚动

java - 结果集耗尽 Oracle 查询

java - 如何实例化同一对象的两个线程,并让对象打印不同的内容

java - 使用 wsimport 生成 Web 服务骨架(服务器端工件)

javascript - 如何在手机和平​​板电脑上自动播放 html 视频?