Search code examples
pythonseleniumselenium-webdriverrobotframeworkrobotframework-ide

How can I get multiple elements and print in Robot Framework- SeleniumLibrary?


${get_t}=    Get Text    //h6[@class='MuiTypography-root MuiTypography-subtitle2']
Log    ${get_t}
${get_t1}=    Get Element Count    xpath://h6[@class='MuiTypography-root MuiTypography-subtitle2']
Log    ${get_t1}
${get_t3}=    Get WebElements    xpath://h6[@class='MuiTypography-root MuiTypography-subtitle2']
Log    ${get_t3}

when I get Count it shows the count but when i print it using Get WebElements it doens't print the text. If I give Get Text it print the first text alone.

enter image description here

Xpath enter image description here


Solution

  • What do you want to achieve - get/print the text of each element? Because Get Webelements does just what its name says - returns you a list of matching elements - selenium element objects. Having that, if you want to print the text of each one, just iterate over the list and call Get Text on each member:

    FOR    ${el}    IN    @{get_t3}
        ${txt}=    Get Text    ${el}
        Log    ${txt}
    END