how to format the data to dicitem properly using robotframework seleniumlibrary?

Viewed 31

I am trying to format the data as below using dicitem using robotframework but am not getting as desired can any one check and please help me out

Website: https://www.w3schools.com/html/html_tables.asp

{"Country": ["Germany", "Mexico", "Austria", "UK", "Canada", "Italy"]
 "Company": ["Alfreds Futterkiste", "Centro comercial Moctezuma", soon..]
 "Contact": ["Maria Anders", "Francisco Chang", soon..]}

But currently am getting like this:

{'Company': ['Alfreds Futterkiste', 'Centro comercial Moctezuma', 'Ernst Handel', 'Island Trading', 'Laughing Bacchus Winecellars', 'Magazzini Alimentari Riuniti']}
{'Contact': ['Alfreds Futterkiste', 'Centro comercial Moctezuma', 'Ernst Handel', 'Island Trading', 'Laughing Bacchus Winecellars', 'Magazzini Alimentari Riuniti', 'Maria Anders', 'Francisco Chang', 'Roland Mendel', 'Helen Bennett', 'Yoshi Tannamuri', 'Giovanni Rovelli']}
{'Country': ['Alfreds Futterkiste', 'Centro comercial Moctezuma', 'Ernst Handel', 'Island Trading', 'Laughing Bacchus Winecellars', 'Magazzini Alimentari Riuniti', 'Maria Anders', 'Francisco Chang', 'Roland Mendel', 'Helen Bennett', 'Yoshi Tannamuri', 'Giovanni Rovelli', 'Germany', 'Mexico', 'Austria', 'UK', 'Canada', 'Italy']}

Am using following code

*** Settings ***
Documentation  This is a sample resource file which provides data to scenarios

Library     SeleniumLibrary
Library     Collections
Library     OperatingSystem

*** Variables ***
${URL}      https://www.w3schools.com/html/html_tables.asp
${DELAY}    0
${BROWSER}  chrome
${HEADER}  table[id='customers'] tbody tr th

*** Keywords ***

Setup chromedriver
  Set Environment Variable  webdriver.chrome.driver  ${CURDIR}/webdrivers/chromedriver.exe

I am on table page
    Open Browser  ${URL}  ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed  ${DELAY}
    Wait Until Element Is Visible  xpath://h3[text()='Example']

I should print table data
    ${index}  Get Element Count  css:${HEADER}
    ${header}  Get WebElements  css:${HEADER}
    ${cols}  Create List
    ${rows}  Create List
    FOR  ${i}  IN RANGE  0  ${index}
        ${col}  Get Text  ${header}[${i}]
        Append To List  ${cols}  ${col}
        @{bodys}  Get WebElements  xpath://table[@id='customers']/tbody/tr/td[${i} + 1]
        FOR  ${body}  IN  @{bodys}
            ${row}  Get Text  ${body}
            Append To List  ${rows}  ${row}
        END
        ${data}  Create Dictionary  ${col}=${rows}
        Log To Console  ${data}
    END
0 Answers
Related