Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning to variables inside Run Keyword If

\   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}

Hi i want to use the GET TEXT activity inside a IF block in FOR but its giving an error stating keyword name cannot be empty help

like image 819
Taimur Avatar asked Nov 22 '25 20:11

Taimur


1 Answers

You can't have a construct ${variable}= Returned Value From Keyword inside a Run Keyword/Run Keyword If because the latter expects everything passed to it to be a keyword - and it considers ${variable} also to be one.

There is one "workaround" - Run Keyword If propagates back up the last returned value in its keyword, and that can be set to a variable. E.g. you can do this:

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

Mind the ELSE in this construct - without it, if the condition is false the variable will be undefined - will be left with a value None (the data type).

Naturally, if the Run Keyword If has more than one steps (like your console logs) you'll have to break it up - a block that "does things", and another (or others) that "assigns values".

I've typed "workaround" in quotes because it isn't really such - it's the way the keyword is designed to be used.

like image 96
Todor Minakov Avatar answered Nov 24 '25 22:11

Todor Minakov