Reputation: 47
i want to know how to display a message in console when an element is not found with robot framework:
I tried this:
S2L.Wait Until Page Contains Element ${checkbox} 10s checkbox not found
It's not working for this element and don't know why. It works for any other element but not for my checkbox.
So for now i have this:
Wait Until Keyword Succeeds 5 times 2 sec S2L.Click Element ${checkbox}
But when it fails it says only the element not found bu i would prefer to code a personalized message.
Any help is welcome. Thank you
Upvotes: 1
Views: 696
Reputation: 833
How about using the error argument available with the Wait Until Page Contains Element keyword?
Wait Until Page Contains Element id=elementId timeout=60s error=Display whatever you want, e.g. Lorem Ipsum...
Upvotes: 0
Reputation: 6961
Although I do think that your problem is something different, your question can be answered. Run Keyword And Return Status
will capture the error and continue and provide a status. Run Keyword If
then allows for using the keyword Fail
and it will also generate a message on the console.
*** Settings ***
Library SeleniumLibrary
Suite Teardown Close All Browsers
*** Test Cases ***
Wait And Click succesfully
Open Browser http://google.com HeadlessChrome
Wait and Click Element name:q This should work
Wait And Click unsuccesfully
Open Browser http://google.com HeadlessChrome
Wait and Click Element name:nobtn This should not work
*** Keywords ***
Wait and Click Element
[Arguments] ${locator} ${message}=None
${status} Run Keyword And Return Status
... Wait Until Keyword Succeeds
... 5 times 2 sec
... Click Element ${locator}
Run Keyword If
... "${status}" == "False"
... Fail ${message}
Upvotes: 2