代码之家  ›  专栏  ›  技术社区  ›  indrajit narvekar

如何在robot框架中将html文本写入文本区域?

  •  0
  • indrajit narvekar  · 技术社区  · 8 年前

    我想将以下代码添加到textarea输入中,我应该如何使用Robot框架来实现这一点?

    <table style="margin-top: 1em; margin-left:1em;">
        <tbody>
            <tr>
                <td><img src="/static/31bc33ac/images/48x48/orange-square.png" style="width: 48px; height: 48px; " class="icon-orange-square icon-xlg"></td>
                <td style="vertical-align:middle">
                    <p><span>Started by user <a href="/user/vkatkar">Vaishali Katkar</a></span></p>
                </td>
            </tr>
            <tr>
                <td><img src="/static/31bc33ac/plugin/metrics/images/48x48/clock.png" alt="" style="width: 48px; height: 48px; margin-right:1em;"></td>
                <td style="vertical-align:middle">
                    <p>This run spent 1 sec waiting in the queue.</p>
                </td>
            </tr>
            <tr>
                <td><img src="/static/31bc33ac/plugin/git/icons/git-48x48.png" alt="" style="width: 48px; height: 48px; margin-right:1em;"></td>
                <td style="vertical-align:middle"><b>Revision</b>: 861b6af99e7899d0b725459417e9fadfa25e2706
                    <ul>
                        <li>develop</li>
                    </ul>
                </td>
            </tr>
        </tbody>
    </table>
    
    1 回复  |  直到 8 年前
        1
  •  3
  •   A. Kootstra    8 年前

    HTML字符串包含许多通常应转义的字符。因此,更容易将其从常规文本文件加载到变量中,然后将该变量输出到所需的textarea元素中。

    在以下示例中,这是使用示例站点完成的:

    填充通知。机器人

    *** Settings ***
    Library    OperatingSystem
    Library    Selenium2Library
    
    Test Setup        Start Browser
    Test Teardown     Close Browser
    Suite Teardown    Close All Browsers
    
    
    *** Test Cases ***
    Fill Textarea with HTML code
        ${file_contents}    Get File    ./htmlcode.txt
        Input Text    name=longtext     ${file_contents}
        Sleep    3s
    
    *** Keywords ***
    Start Browser
        Open Browser    http://www.echoecho.com/htmlforms08.htm    Chrome
    

    htmlcode。txt文件

    Contains the HTML code you want to insert.