0

这是我的代码:

<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 和描述作为输出。

4

1 回答 1

0

使用示例作为基础,我无法复制您的问题,因为使用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.机器人

*** 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

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

在此处输入图像描述

于 2020-08-22T19:42:02.780 回答