温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - How can I get multiple elements and print in Robot Framework- SeleniumLibrary?
python robotframework selenium selenium-webdriver robotframework-ide

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

发布于 2020-04-10 09:02:07
${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}

当我得到Count时,它会显示计数,但是当我使用Get WebElements打印它时,它不会打印文本。如果我输入Get Text,则仅打印第一个文本。

在此处输入图片说明

Xpath 在此处输入图片说明

查看更多

提问者
Pradap Pandian
被浏览
140
Todor Minakov 2020-02-01 19:50

您要实现什么-获取/打印每个元素的文本?因为Get Webelements确实如其名称所说-向您返回匹配元素的列表- selenium 元素对象。这样,如果您想打印每个文本,只需遍历列表并调用Get Text每个成员即可:

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