selenium - 在 Run Keyword If - Robot Framework 中处理多个语句

标签 selenium robotframework

只有在使用 Robot Framework 传递条件时,我才需要执行多个语句

请看代码:注意这是一个示例代码

*** Settings ***
Library    Selenium2Library
Library    Collections

*** Keywords ***
Parent Routine
    ${isElementExist}    Run Keyword And Return Status    Element Should Be Visible   id=txt1
    Run Keyword If    ${isElementExist}     click element      id=btn1
    Run Keyword If    ${isElementExist}     click element      id=btn2
    Run Keyword If    ${isElementExist}     click element      id=btn3

*** Test Cases ***
Sample Test Case
    [Documentation]   Simple test for If Condition
    Parent Routine

我不知道如何将click element的所有语句捆绑在Run Keyword If ${isElementExist}的范围内。

请帮助我。

最佳答案

当然我们可以在 Run Keyword If 中执行多个语句

If 语句应该是

Run Keyword If    ${isElementExist}    Run Keywords    click element      id=btn1
...   AND    click element      id=btn2
...   AND    click element      id=btn3

完整代码为

*** Settings ***
Library    Selenium2Library
Library    Collections

*** Keywords ***
Parent Routine
    ${isElementExist}    Run Keyword And Return Status    Element Should Be Visible   id=txt1
    Run Keyword If    ${isElementExist}    Run Keywords    click element      id=btn1
    ...   AND    click element      id=btn2
    ...   AND    click element      id=btn3

*** Test Cases ***
Sample Test Case
    [Documentation]   Simple test for If Condition
    Parent Routine

关于selenium - 在 Run Keyword If - Robot Framework 中处理多个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44780327/

相关文章:

python - 在 RobotFramework 中执行测试后,有没有办法让浏览器窗口保持打开状态?

python - 通过网页上的多个 xpath 元素进行过滤

selenium - 如何通过Docker Compose链接Selenium服务器

html - 获取跨度文本的xpath

robotframework - 如何实现Jira Xray + Robot Framework?

python - 测试电子应用程序: unable to initialize test as prescribed with Robot Framework

python - 如何将参数发送到_init_

robotframework - 使用 .robot 文件而不是 .txt 文件进行测试有什么好处

python - 给定一个 (Python) Selenium WebElement,我可以获得 innerText 吗?

java - Jenkins 无法为我的 Selenium 项目编译 Maven