Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I want to run Keyword if Element is visible. E.g I want to check that if a button is visible on the page then run particular Keyword. Below is my code. Create button is Keyword and want to run if CreateButton is visible on the page otherwise not.

Create Button
    Sleep    10s
    Click Element    ${CreateButton}

Create Case with Subject
    Sleep    15s
    ${CreateButtonVisible} =    Page Should Contain Element    ${CreateButton}
    Run keyword If    ${CreateButtonVisible}    Create Button
share|improve this question

2 Answers 2

Based on the example of RF keywords list, you should write the condition, in your case should be ${CreateButtonVisible} == 'PASS'

Run Keyword If ${CreateButtonVisible} == 'PASS' Create Button

share|improve this answer
    
You probably will need quotes around the first part of the expression: '${CreateButtonVisible}' == ... –  Bryan Oakley Aug 9 at 12:28

It seems like you don't want to report error if element was not found. In such case, the most straight-forward way is to run the keyword and ignore errors if element is not found:

Run Keyword And Ignore Error    Click Element    id=element_id

Also, hard-coding sleep intervals can make your tests slow and flaky. Using Wait Until Page Contains is better.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.