【问题标题】:Multi Line Text Area using htmlunit使用 htmlunit 的多行文本区域
【发布时间】:2014-07-31 00:19:25
【问题描述】:

要求:我在网页中有一个带有一些默认值的多行文本区域,我需要更改该值并提交表单。文本区域定义如下。

<textarea id="editorarea" name="_editedtext"
         class="editor"
       onkeyup="getSuggestions(this.id)"
       onclick="setCursorPos(this.id)"
      onchange="setCursorPos(this.id)"
          rows="20" cols="80">! Lorem ipsum" text is derived
from sections 1.10.32–3 of Cicero's De
finibus bonorum et malorum (On the Ends of Goods

问题:当我从一个字符串为 textarea 设置文本时,它变成如下所示:

<textarea id="editorarea" name="_editedtext"
         class="editor"
       onkeyup="getSuggestions(this.id)"
       onclick="setCursorPos(this.id)"
      onchange="setCursorPos(this.id)"
          rows="20" cols="80">Lorem ipsum" text is derived&lt;br&gt;from sections 1.10.32–3 of Cicero's De &lt;br&gt;| LPAR Name If Remote:| N/A1&lt;br&gt;\\ &lt;br&gt;! Endpoints&lt;br&gt;finibus bonorum et malorum (On the Ends of Goods'&lt;br&gt;         

所以内容变成单行,换行符没有被识别,我试过 "\n" , "
" 都没有工作。

我将我的输入放在一个数组列表中,并将它们转换为单个字符串,如下所示:

public static void createString(){
    StringBuilder sb = new StringBuilder();
    for(String s : finalModifiedList){
    sb.append(s);
sb.append("<br>");   
    }
    finalString =sb.toString();

并设置textarea内容如下

HtmlTextArea  erfTextarea = textAreaForm.getTextAreaByName("_editedtext");
erfTextarea.setText(content);

TextArea 字符集是:UTF-8

请告诉我如何使用 htmlunit 输入多行文本

【问题讨论】:

  • 你找到解决办法了吗?

标签: java javascript html htmlunit


【解决方案1】:

在 createString() 中将 sb.append("&lt;br&gt;"); 替换为 sb.append("\n");

【讨论】:

    猜你喜欢
    • 2011-10-20
    • 2015-03-07
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多