Web table parsing

It is possible to parse the web table on a page to validate the records and do the action.

To Get the row count

 

${rowCount}=    Get Element Count    //table[@id='webtable-table']/tbody/tr

 

To Get the column count

 

${colCount}=    Get Element Count    //table[@id='webtable-table']/tbody/tr[1]/td

 

To iterate each row and cell

 

FOR   ${rowIndex}     IN RANGE     1      ${rowCount} + 1
     ${curText}      Get Text     //table[@id='webtable-table']/tbody/tr[${rowIndex}]/td[${rowIndex}]
     Log     ${curText}
     Run Keyword If     '${curText}' == '${cellText}'     Click      locator
     Exit For Loop If    '${curText}' == '${cellText}'
END

 

Note:: To parse each cell, there should be FOR loop inside FOR loop, but it is not supported in the robot framework. Instead of having a nested loop, create a separate function/keyword and call the function inside the for loop do the trick.

 

${rowCount}=    Get Element Count    //table[@id='webtable-table']/tbody/tr
${colCount}=    Get Element Count    //table[@id='webtable-table']/tbody/tr[1]/td
FOR   ${rowIndex}     IN RANGE     1      ${rowCount} + 1
         Nested loop  ${rowIndex}   ${colCount}
END
    
*** Keywords ***
Nested loop
    [Arguments]   ${rowIndex}   ${colCount}
    FOR  ${colIndex}  IN RANGE     1      ${colCount} + 1
            ${curText}      Get Text     //table[@id='webtable-table']/tbody/tr[${rowIndex}]/td[${colIndex}]
            Log     ${curText}
    END

 

 

Related Tutorials