Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework If element is visible execute a keyword

I have a page that may and may not contain a certain element that will affect all the xpaths.

I need to run a "Run Keyword If" to identify if this element exists and if so to execute another keyword.

I tried to set the "Page Should Contain Element" and "Element Should Be Visible" as variables and pass it in the If statement but it only return None.

What can I use to identify an element in a page?

like image 542
PurpleBeni Avatar asked Jun 03 '15 14:06

PurpleBeni


Video Answer


2 Answers

I experienced the same issue, I use this solution:

${present}=  Run Keyword And Return Status    Element Should Be Visible   id=my-element
Run Keyword If    ${present}    My Cool Keyword
like image 115
Bruno Bossola Avatar answered Sep 21 '22 07:09

Bruno Bossola


I had similar situation and I used the script below:

${IsElementVisible}=  Run Keyword And Return Status    Element Should Be Visible   ${Element1}
Run Keyword If    ${IsElementVisible}  MyCase1  ELSE  Click Element  ${Element2}
like image 45
asha cr Avatar answered Sep 19 '22 07:09

asha cr