can't able to get the text from the html table using robot framework

1.2k views Asked by At

Here is my code:

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

I need to get ID as output for xpath_1 and Description as output for xpath_2. but when I try to get output for below code I am getting:

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

The following error I am getting for this method

Keyword 'SeleniumLibrary.Get Table Cell' expected 3 to 4 arguments, got 1.

(or)

${table_data}=  Get Text  ${xpath_1}

empty space is coming as output for this method

Please suggest me how to get ID and Description as output from the above table using robot framework.

1

There are 1 answers

0
A. Kootstra On

Using the example as a basis I've been unable to replicate your problem because when using Get Text keyword actually provides the desired ID value. Below are the files and approach for replicating this in your own setup.

Create a new file:

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>

In the directory where this file goes execute the following command:

python -m http.server 8989

I use RED, but other IDE's or text editors will work too. Create a robot file

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

Using the debugger in RED I paused on the No Operation keyword line.

enter image description here