如何在Robot Framework SeleniumLibrary中获取多个元素并打印?

2024-05-20 14:36:54 发布

您现在位置:Python中文网/ 问答频道 /正文

${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}

当我获取计数时,它会显示计数,但当我使用get WebElements打印它时,它不会打印文本。如果我给Get Text它会单独打印第一个文本

enter image description here

Xpathenter image description here


Tags: text文本loggetrootxpathclass计数
1条回答
网友
1楼 · 发布于 2024-05-20 14:36:54

您希望实现什么-获取/打印每个元素的文本?因为Get Webelements只做它的名字所说的-返回匹配元素的列表-selenium元素对象。 这样,如果您想打印每个成员的文本,只需在列表上迭代并对每个成员调用Get Text

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

相关问题 更多 >