在 Web 应用程序的 HTML 中,有以下代码:
<input type="text" name="prettyTime" id="prettyTime" class="ui-state-disabled prettyTime" readonly="readonly">
显示时间的字符串实际上显示在页面上。
在 Selenium WebDriver 中,我有一个 WebElement
对象引用 <input>
使用:
WebElement timeStamp = waitForElement(By.id("prettyTime"));
我想获取 WebElement
的值,换句话说,就是页面上打印的内容。我尝试了所有 WebElement
吸气剂,但没有任何东西可以检索用户看到的实际值。
原文由 jamesfzhang 发布,翻译遵循 CC BY-SA 4.0 许可协议
这有点hacky,但它有效。
I used
JavascriptExecutor
and added adiv
to the HTML, and changed the text in thediv
to$('#prettyTime').val()
然后我使用 Selenium 检索
div
并获取它的值。测试值的正确性后,我删除了刚刚创建的div。