【问题标题】:How to retrieve the contents of a text area where the contents are not represented under the html code如何检索在html代码下没有表示内容的文本区域的内容
【发布时间】:2014-07-28 12:22:27
【问题描述】:

我有一个文本区域,其中的内容未在 HTML 代码下表示。 代码如下所示:

<fieldset>
<legend>Ping Results</legend>
<textarea id="displayArea" cols="80" rows="10" name="displayArea"></textarea>
<table class="content-form" summary="Layout: Ping Results">
<tbody>
<tr> </tr>
</tbody>
</table>
</fieldset>

单击 UI 上的按钮后,内容会出现在文本区域中。

喜欢: PING 10.106.214.55 (10.106.214.55) 56(84) 个字节的数据。 来自 10.106.214.55 的 64 个字节:icmp_seq=1 ttl=64 time=0.072 ms

--- 10.106.214.55 ping 统计 --- 1个包发送,1个接收,0%丢包,时间0ms rtt min/avg/max/mdev = 0.072/0.072/0.072/0.000 ms

我试过了:

WebElement ele = driver.findElement(By.id("displayArea")); String text = ele.getAttribute("value");

和 getText() 也是如此。 两者都不返回。 请帮忙。

【问题讨论】:

    标签: java selenium


    【解决方案1】:

    我们可以访问内置的 value 属性来获取在 TextArea 中输入的值。代码如下:

    String value = ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML", driver.findElement(By.id("displayArea"))).toString();
    

    让我知道这是否有帮助!

    【讨论】:

    • 嗨 mfsi_sitamj,使用上面的代码行,我得到的方法 executescript 未定义为 WebDriver 类型。请建议。
    猜你喜欢
    • 2019-02-23
    • 2011-11-18
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多