how do i do a if condition if a element is present?

1,975 views
Skip to first unread message

Daniel Almeida

unread,
Jun 2, 2015, 9:26:58 AM6/2/15
to robotframe...@googlegroups.com
Hi all,

I'm trying to do something like this?

If element is presentd:
      do something

But i'm not finding a keyword that does that.. All keywords have "should" word.. But don't have something specific, like... Page Contains.. the keyword is Page Should Contains..

I'm "clicking" on a lot of elements to input some values in a form inside of this elements.. but not all forms are the same and have some extra elements.. So i need to check if a element is present, then i input something..


thanks,

daniel

Laurent Bristiel

unread,
Jun 3, 2015, 4:14:15 AM6/3/15
to robotframe...@googlegroups.com
Hi,

you can do something like that:

${element_exists} =    Run Keyword And Return Status    Page Should Contain Element    id=whatever
Run Keyword If    ${element_exists}    do something


Hope this helps,
Laurent Bristiel

Daniel Almeida

unread,
Jun 3, 2015, 7:37:16 AM6/3/15
to robotframe...@googlegroups.com
Hi man... thanks... I posted here but i forgot to post the solution that i did..

I did something similar that you suggested, but the difference i used Run Keyword And Ignore Errors:

${status}                               ${error}                                       Run Keyword And Ignore Error    Page Should Contain Element    id
Run Keyword If                     '${status}' == 'PASS'                    Input Text                                  //*[@id='src_ip']                         id


Because i didn't whant to the tests stops if he didn't find this specific fild... so for all fields in the form that changes when i click in a elment of a list..

But thanks a lot for your contribution,


daniel.
Reply all
Reply to author
Forward
0 new messages