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

标签 python selenium selenium-webdriver robotframework 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}

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

enter image description here

Xpath enter image description here

最佳答案

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

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

关于python - 如何在 Robot Framework- SeleniumLibrary 中获取多个元素并打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60016277/

相关文章:

python - 如何将 gamlss 与 rpy2 一起使用

python - 在 Python 中临时更改变量的值

python - 组合重新标记 re.IGNORECASE、re.MULTILINE 和 re.DOTALL

python - 我是否需要仅在构建 ATLAS 时或始终关闭 CPU 限制?

python - Selenium 无法通过 id 访问网络元素(python)

在Maven中添加Selenium-java-2.31.0库后Java代码抛出异常

java - 将 Selenium WebDriver 与 Java 结合使用

Python webdriver : driver. get(URL) 无法在单元测试中打开 - 通过控制台工作

java - 使用selenium提取<br>标签前后的数据

firefox - 在 Firefox 中自动下载 PDF