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
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.
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?
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