How to verify if a checkbox is selected or not?

Hi All,

I am new to appium and trying to automate few basic cases using python. I was trying to verify if a checkbox is selected is not. Checked the web for it and found is_selected() attribute for verifying the state.

But when I use it, appium throws an error as follows:

el = self.driver.find_elements_by_id(‘com.twitter.android:id/phone_number_addr_book_checkbox’).is_selected()
AttributeError: ‘list’ object has no attribute ‘is_selected’

Can anybody please help me in this regard?

Also is there any feature for appium to take the error/fail scenario screenshot so that it can be viewed later for debugging purpose?

Platform - Android
Appium version - 1.2.2
Real Device
Client langauage - python
OS - Win 8.1

Hey Dipak,

I am also new with appium but i can suggest a debugging method for you.

First get ipython if you don’t have it yet. Than ipdb.

Now in your test script, put the debugger and set the trace at the line just after the element search, like this :

el = self.driver.find_elements_by_id(‘com.twitter.android:id/phone_number_addr_book_checkbox’)
import ipdb; ipdb.set_trace()

You will be at the interpreter at that line, check and see what el is, it seems a list, you will see the vars that it carries.
than you can check the items in the list and try to apply is_selected() to the one you need.

PS: Remove the is_selected() call in that element.

Regards,

Emir

1 Like

Hi Emir,

I got the solution for this by using is_enabled() attribute.

Thanks for the post. As you have mentioned, el is a list and I will tryout your debugging suggestion to my script. This will help me a lot for debugging issues.

For this query I am still waiting for any answers:

Is there any feature for appium to take the error/fail scenario screenshot so that it can be viewed later for debugging purpose?

Br,
Dipak

1 Like

Hi again Dipak,

As I am also new, I am using something that i came up with, which is i hardly believe the optimized solution…
But anyways just for the sake of providing a solution, this is the one i use:

def test_case_blabla(self):
    '''Docstr
    '''
    try:
        # test code goes here
    except Exception as e:
        current_datetime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        self.driver.save_screenshot('failure_screenshots/'+
                                    self.TEST_SUITE_NAME+'_%s.png' %current_datetime)
        self.fail(e)

PS: Replace self.TEST_SUITE_NAME with anything you like

Regards,

Emir

Hey Emir,

Thanks for the code snippet. I will try it out.

It would be great if the tool can generate a HTML log file and the failure screen capture along with all the steps executed.

@jlipps, @jonahss can it be taken as a feature request?

No, this isn’t an appropriate feature request for the Appium server. Unfortunately the server has nothing to do with your test code here.

Thanks Jonathan for the response.

This might sound like a silly question, but I would like to know how the server logs are generated?

Waiting for your reply.

Br,
Dipak

Server logs generated?

We have code all over which basically says logger.info("we did some stuff") or logger.error("oh no! an erro!")
Maps to stdout I assume.

Thanks Jonah for the info.