在Run Keyword If中分配给变量

时间:2020-02-17 18:46:57

标签: robotframework

\   Run Keyword If    ${i} == 7    log to console     Testing Variant 1
\   ${is visible}=    Run Keyword And Return Status    Element Should Be Visible   (//li[@class='_8HqL0'])[${i}]
\   Run Keyword If    ${is visible}  Run keywords
\   ...  Scroll Element Into View    (//li[@class='_8HqL0'])[${i}]
\   ...   AND     Click Element     (//li[@class='_8HqL0'])[${i}]
\   ...   AND     sleep  2s
\   ...    set variable   ${Ad_Path}  Get Text  //*[@class='rui-3blDo _1Uh38 _27AdP']
\   ...   AND     log to console    ${Ad_Path}

嗨,我想在FOR的IF块中使用GET TEXT活动,但是它给出了一个错误,指出关键字名称不能为空帮助

1 个答案:

答案 0 :(得分:3)

您不能在${variable}= Returned Value From Keyword / Run Keyword中包含构造Run Keyword If,因为后者希望传递给它的所有内容都是关键字-认为${variable}也是一个。

有一个“解决方法”-Run Keyword If将其关键字中最后返回的值传播回去,并且可以将其设置为变量。例如。您可以这样做:

${variable}=     Run Keyword If    ${condition}    Returned Value From Keyword    ELSE    Set Variable    other value

在此构造中注意ELSE -如果没有,条件为假,则该变量将是不确定的–将保留值None(数据类型)。

自然地,如果Run Keyword If有多个步骤(例如控制台日志),则必须将其分解-一个“做某事”的块,另一个(或其他)“分配值”的块“。

我在引号中输入了“替代方法”,因为它并非如此-这是设计关键字使用的方式。

相关问题