Assign variable for IF statement

Hi.
After searching in doc I’m looking for some advice here, please help.

I try to add some logic using IF ELSE statement in my tests and stuck with assignments the variable the IF statement.

Brief overview:
I am testing create functionality in CMS, new record ‘name’ have to be unique value.
Before creating I have to check if the ‘name’ I choose is free and in case it is not free I delete record before creating, so here is the code snippet:

*** Settings ***
Resource …/…/resource.robot

*** Keywords ***
Check server not exist before attempt to create it
Go to CMS
Press Keys ${SearchField} ${hostname_value} RETURN
${count} = Get Element Count ${ThereIsNoRecordFound}
IF ${count} == 0
Delete server
END

My questio is how to assign ${count} successfully any time, no matter if there is an ${ThereIsNoRecordFound} or not on the page.
The main issue for me now - when there is no locator ${ThereIsNoRecordFound} on the page - test fails.
My expectation is - assign ‘0’ or ‘1’ to ${count} without error when there is no such locator on page (when there is something found and I have to delete record before creating new one in test)

Instead of counting the ${ThereIsNoRecordFound} element, just check if it is visible or not. If it is not visible, delete the server.

Get Element Count failing if there are no elements sounds strange. I agree it should return 0 in that case. What library you are using? You could consider submitting a bug to its issue tracker.

${count} =    Run Keyword And Return Status    Element Should Not Be Visible    ${NoDataAvailable}
IF                                    ${count}
Delete server
END

Works for me :slight_smile:

pip list | grep selenium
robotframework-selenium2library 3.0.0
robotframework-seleniumlibrary  5.1.3
selenium                        4.0.0

Rechecked, Get Element Count return 0 or 1, no bug needed.