0

I am trying to get the status of Checkbox using androidviewclient

lock = vc.findViewWithText('Lock SIM card')
if (lock.isChecked()):
    print "Enabled"
else:
    print "Disabled"

this always returns False .

can anybody tell me how to get the status of checkbox

user
  • 65
  • 1
  • 11

2 Answers2

1

That's because lock is not the ckeckbox. Lock is the text view containing "Lock SIM card". You need to use hierarchyviewer or uiautomatorviewer to see the layout of the UI.

The UI looks something like:

(0) Linear layout
    (1) Relative layout
        (0) TextView "Lock SIM card"
        (1) TextView "Require PIN to use phone"
    (2) Linear layout
        (0) CheckBox

So you need to do something like:

linear_layout = lock.parent.parent
check_box = linear_layout.children[2].children[0]

It's not straight forward, but I used this in the past and worked. Please note that the ViewClient version that I used was 2.3. Now it has evolved to 4+.

Gabriel Porumb
  • 1,661
  • 1
  • 12
  • 21
  • I have already stated the changes needed. It's right under "you need to do something like" . – Gabriel Porumb Oct 23 '13 at 07:40
  • when i did as u suggested , i see the below error : check_box = linear_layout.children()[2].children()[0] TypeError: 'list' object is not callable – user Oct 23 '13 at 08:12
  • I edited the answer. You need to remove the () from children(). – Gabriel Porumb Oct 23 '13 at 10:30
  • Now i see this error : check_box = linear_layout.children[2].children[0] IndexError: list index out of range – user Oct 23 '13 at 11:06
  • Hi , similar to the checkbox how can i get the status of radio button . i tried to see the layout of ui using hierarchyviewer , it looks some thing like this : (0) Linear layout (1) Linear layout (0) CheckedTextView "All Calls" (1) CheckedTextView "When roaming" But i dont see anything for the radio button in the layout . Please help . – user Nov 05 '13 at 07:23
  • Could you be more specific? What window are you looking at? What menu option. I need more details to figure out where to look. – Gabriel Porumb Nov 05 '13 at 14:32
  • Here is the navigation for the window i am looking at : Phone > Settings > GSM call settings > Call Barring > Incoming barring > All calls -----> this is the menu option which has an Radio button , for which i have to check if this option is enabled . – user Nov 06 '13 at 03:11
  • I do not have such a menu entry, but I used the emulator and went to Settings -> More -> Mobile Networks -> Access Point Names and there was a radio button. Using uiautomator viewer I spotted a RadioButton UI element. Just expand the whole layout tree and look for the specific element. – Gabriel Porumb Nov 06 '13 at 12:08
0

This might work:

 vc.dump()
 lock = vc.findViewWithText('Lock SIM card').getParent().getChildren()                                                                                                                                                   [2].getChecked()
    if lock != True:
       print 'Lock SIM card not enabled...'
       vc.dump()
       vc.findViewWithText('Lock SIM card').touch()
    else:
       print 'Lock SIM card already enabled...'
Marcin Koziński
  • 10,835
  • 3
  • 47
  • 61
Arun Sai
  • 1
  • 3