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

Pra*_*ian 3 python selenium robotframework selenium-webdriver robotframework-ide

${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}
Run Code Online (Sandbox Code Playgroud)

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

在此处输入图片说明

Xpath 在此处输入图片说明

Tod*_*kov 5

你想实现什么 - 获取/打印每个元素的文本?因为Get Webelements正如它的名字所说的那样 - 返回一个匹配元素的列表 - selenium 元素对象。有了这个,如果你想打印每个人的文本,只需遍历列表并调用Get Text每个成员:

FOR    ${el}    IN    @{get_t3}
    ${txt}=    Get Text    ${el}
    Log    ${txt}
END
Run Code Online (Sandbox Code Playgroud)