How to Select checkbox in Appium using Python if there is no unique ID/Text/Class name


Hi I am trying to click checkbox. the below is my code

from appium import webdriver

import time from selenium.webdriver.common.action_chains import ActionChains

from import By

desired_cap = dict(


) driver = webdriver.Remote(“”, desired_cap) driver.find_element(By.XPATH, “//android.widget.TextView[@text=‘Accessibility’]”).click() driver.find_element(By.XPATH, “//android.widget.TextView[@text=‘Accessibility Node Querying’]”).click() time.sleep(2) chk= driver.find_elements(By.XPATH, “//android.widget.CheckBox”)

for i in chk: if i == 2:

By above code if i give i am able to click all checkboxes. But if i want to click single check box i am not getting solution.

Why don’t you find the ‘Do Laundry’ element and then just click then next check box. There are 2 solutions in this link, I’m sure you can search up more:

+1 the suggestion by @wreed to get the next element after the “Do Laundry” text. You might ask the developers to dynamically add ID’s if this list never really changes. But for this kind of listing job, it should be stable enough to select element “next to”, since if it ever breaks, it will break for all the elements in the grid anyway.

Hi Wreed thanks for the reply. I just started appium learning. I know how it works in selenium but not getting in appium. Could you please eloborate the ‘Do laundry’ element ?

you want to go and open inspector and show us the xml for the 2 elements, basically the outer element will be a row I suspect - like I highlight in yellow

It will help to review the syntax

Then you need to read up on the specific selectors. This is one of the better “short guides” , just scroll down a ways. If you “paste” the XML for the nodes into the thread, we can take a guess at an xpath that will give you some clues. Inspector lets you test an xpath, so you can build one and try it. It’s going to look a lot like :

elem = driver.find_element(By.XPATH, '//android.widget.TextView[contains(@text,"Do Laundry")]/following-sibling::....magic-here....')

Thank you :slight_smile: Somehow i am able to achieve it by using Xpath
driver.find_element(By.XPATH, “//*[@class=‘android.widget.CheckBox’ and @bounds=’[525,865][615,949]’]”)

But my question is bound value is constant for device to device? As i am testing it on a real device.

1 Like

Getting with hard coded boundaries is perfect if you are only going to use one device and os version and these will never change.

Sadly, I don’t think you looked at the link I provided.

@wreed yes i read and tried, but could not succeed. I am still learning appium. In Selenium somehow i can able to use all the above methods. But in mobile it’s a little difficult. I am learning and thanks for the response.

1 Like