3

I am using robot framework. How can I test if a checkbox is selected? I want to run a keyword if a checkbox is selected like:

 ${checked} = Checkbox Should Not Be Selected xpath=.//*[@id='0,1,1,6']/td[11]/input
 Run Keyword if '${checked}' Click Element xpath=.//*[@id='0,1,1,6']/td[11]/input and wait

i.e. to click there if is not already clicked.

(The code of above is wrong, I know)

asked Feb 22, 2013 at 10:54

3 Answers 3

1

Use Run Keyword And Return Status

It runs the given keyword with given arguments and returns the status as a Boolean value. This keyword returns True if the keyword that is executed succeeds and False if it fails. This is useful, for example, in combination with Run Keyword If. If you are interested in the error message or return value, use Run Keyword And Ignore Error instead.

answered Jun 5, 2013 at 10:03
0

From: Selenium2Library documentation.

Keyword: Checkbox Should Be Selected

Arguments: locator

Documentation: Verifies checkbox identified by locator is selected/checked. Key attributes for checkboxes are id and name. See introduction for details about locating elements.

Bence Kaulics
1,00712 silver badges22 bronze badges
answered Feb 22, 2013 at 12:33
2
  • Thanks for answering. As you can see I am using "Checkbox should be selected" in my code (in fact I am using the negation). This command works like an assertion and not a question. When the assertion fails the test stops. I want to ask if the checkbox is checked and not to assert that the checkbox should be checked. Commented Feb 24, 2013 at 7:24
  • As mentioned in the other answer, "trap/wrap" the assertion by calling it via Run Keyword And Return Status which converts the pass/fail into a True/False return flag. Commented Jun 18, 2020 at 17:16
0

You can try:

${isCheck} = Run Keyword And Return Status Checkbox Should Be Selected xpath=.//*[@id='0,1,1,6']/td[11]/input
Bence Kaulics
1,00712 silver badges22 bronze badges
answered Aug 18, 2020 at 8:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.