Search code examples
pythonrobotframework

Robotframework -: How check if element is enabled then click on it ,else move to next keyword


To check if element is enabled then click on it ,else log some message without failing script-:

run keyword if element should be visible ${accounts_per_page} click on acc_per_page

... ELSE IF LOG "Dropdown is not enabled"

I am getting below error -: Evaluating expression 'element should be visible' failed: SyntaxError: invalid syntax (, line 1)


Solution

  • You should consider redesigning your test. If you absolutely have to you can use keyword Run Keyword And Ignore Error capture the return value and use it as a condition for your next test step with keyword Run Keyword If.

    *** Test Cases ***   
    Example                
        ${output}=    Run Keyword And Ignore Error    Possible Failure
        Log    ${output}[0]
        Run Keyword If    '${output}[0]'=='FAIL'    Keyword With Next Step
    

    If you use robot framework 5.0 you can use the newly added try/catch functionality example taken from the resource.

    *** Test Cases ***
    First example
        TRY
            Some Keyword
        EXCEPT    Error message
            Error Handler Keyword
        END
        Keyword Outside