robotframework - 如何在机器人框架的 FOR 循环中使用 if/else 条件

标签 robotframework

这是我的代码:

:FOR    ${a}    IN RANGE    2    ${Row_Count}

\    Run Keyword If    '${temp}'== 'True'    Click Link    xpath=//table[@id='listAllSTR']/tbody/tr[${a}]/td[2]/a    and 
\    ...    Screen validation for Answered    ${STR_detail}    and
\    ...    ELSE    Continue For Loop
\    Run Keyword If    ${a}>${Row_Count}   Exit For Loop**

当 if 条件通过时(即 if '${temp}'== 'True'),我需要单击一个链接,但出现错误提示

Keyword 'Selenium2Library.Click Link' expected 1 argument, got 5.

我不知道该怎么办。

谁能帮帮我?

最佳答案

关于问题。

您在 if 语句中执行了多个关键字,因此它将其他关键字作为第一个关键字的参数。

解决方案

您可以创建自定义关键字并向其添加其他关键字。在您的 if 语句中使用此自定义关键字。请参见下面的示例。

*** Keywords ***
Custom Keyword From If
    [Documentation]    Keywords documentation.
    keyword1
    keyword2

*** Test Cases ***
Test Custom Keyword
    Run Keyword If    '${a}'=='True'    Custom Keyword From If

注意:

要执行多个关键字,机器人具有关键字“run keywords”,请参阅文档 link

关于robotframework - 如何在机器人框架的 FOR 循环中使用 if/else 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53774850/

相关文章:

python - 无法在 RobotFramework 中存储变量值

python - Robot Framework - 查询返回的关键字类型

python-2.7 - Pabot - 无法运行并行机器人框架测试

python - 在Robot Framework中,在测试用例拆卸阶段,如何检查当前测试用例是失败还是通过?

python - 如何使用 Python 2.7 和 Robot Framework 2.9 开始使用 Edge webdriver

java - 机器人框架未拾取关键字实现

python - 如何让方法在后台运行

testing - 如何在机器人框架中设置多级测试设置/拆卸

arrays - 创建和使用二维数组

python - 使用 API 时使 log.html 更加详细