Search code examples
androidrubyrspeccapybaraappium

Check if checkbox is unchecked


I am trying to write a test that checks if a checkbox is checked or not, if not checked what method will I use to have it checked.

I already have written a code that checks a checkbox,

driver.find_element(:id, 'id_of_the_element').click();

but I still want to check if it was checked or not also for other test case

TYIA!


Solution

  • I think you are expecting the code snippet in Ruby since wrote the snippet for ruby.This code works if you want to check the unchecked checkbox. You can modify if you need more changes inside that.

        element=driver.find_element(:id, 'id_of_the_element');
        if(element.attribute("checked")=="false")
        {
            element.click();
        }