【问题标题】:can't able to get the text from the html table using robot framework无法使用机器人框架从 html 表中获取文本
【发布时间】:2020-12-09 11:11:52
【问题描述】:

这是我的代码:

<div class="table row column" xpath="1">
    <div class="table__head">
      <div class="table__row">
        <div class="table__cell sys-log__col-wrapper sys-log__col-id">
          <div class="column small-2 sort_button_wrapper">
            <button class="sort-ascending" ng-click="sortBy('Id', false)"></button>
            <button class="sort-descending" ng-click="sortBy('Id', true)"></button>
          </div>
          ID
        </div>
        <div class="table__cell sys-log__col-wrapper sys-log__col-desc">Description</div>
      </div>
    </div>


${xpath_1} = //div[@class="table__row"]/div[1]
${xpath_2} = //div[@class="table__row"]/div[2]

我需要将 ID 作为xpath_1 的输出,并将描述作为xpath_2 的输出。但是当我尝试获取以下代码的输出时,我得到了:

${table_data}=  Get Table Cell  ${xpath_1}

此方法出现以下错误

关键字“SeleniumLibrary.Get Table Cell”需要 3 到 4 个参数,得到 1 个。

(或)

${table_data}=  Get Text  ${xpath_1}

这个方法的输出是空白

请建议我如何使用机器人框架从上表中获取 ID 和描述作为输出。

【问题讨论】:

  • 鉴于 html 中没有 &lt;table&gt; &lt;/table&gt;,我不希望 Get Table Cell 工作。基于documentation,它还提供了有关它所需的其他属性的信息。你试过Get TextGet Value 直接检索它们吗?
  • 我已经尝试使用 Get Text,它返回空白空间,而对于 Get Value,我得到 None
  • 您能否通过edit 功能将您尝试过的确切命令添加到您的问题中?这样我们就可以更好地了解正在发生的事情。

标签: robotframework robotframework-sshlibrary robotframework-swinglibrary robotframwork-whitelibrary


【解决方案1】:

使用示例作为基础,我无法复制您的问题,因为使用 Get Text 关键字实际上提供了所需的 ID 值。以下是在您自己的设置中复制它的文件和方法。

创建一个新文件:

div_value.html

<html>
<body>
<div class="table row column" xpath="1">
    <div class="table__head">
      <div class="table__row">
        <div class="table__cell sys-log__col-wrapper sys-log__col-id">
          <div class="column small-2 sort_button_wrapper">
            <button class="sort-ascending" ng-click="sortBy('Id', false)"></button>
            <button class="sort-descending" ng-click="sortBy('Id', true)"></button>
          </div>
          ID774747474
        </div>
        <div class="table__cell sys-log__col-wrapper sys-log__col-desc">Description</div>
      </div>
    </div>
 </div>
 </body>
 </html>

在此文件所在的目录中执行以下命令:

python -m http.server 8989

我使用 RED,但其他 IDE 或文本编辑器也可以。创建机器人文件

div_value.robot

*** Settings ***
Library    SeleniumLibrary    

*** Variables ***
${xpath_1}     //div[@class="table__row"]/div[1]
${xpath_2}     //div[@class="table__row"]/div[2]

*** Test Cases ***
Retrieve DIV Value
    
    Open Browser 
    ...    url=http://127.0.0.1:8989/div_value.html
    ...    browser=headlesschrome

    # ${table_data}=  Get Table Cell  ${xpath_1}
    ${table_data1} =  Get Text   ${xpath_1}
    ${table_data2} =  Get Value  ${xpath_1}
    No Operation
    [Teardown]    Close All Browsers

在 RED 中使用调试器时,我在 No Operation 关键字行上暂停了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-24
    • 2020-10-29
    • 2018-08-03
    • 2017-04-05
    • 2017-11-01
    • 2017-07-23
    • 2020-11-30
    • 2017-11-22
    相关资源
    最近更新 更多