Selecting element by content-desc value with Python


I’m having issues selecting an element in my app by content-desc value. The value in that field is “pay now”. I tried all the following:

pay_now_button = driver.find_element_by_android_uiautomator(‘new UiSelector().description(“pay now”)’)
pay_now_button = driver.find_element_by_name(‘pay now’)
pay_now_button = driver.find_element_by_accessibility_id(‘pay now’)
pay_now_button = driver.find_element_by_id(‘pay now’)

In all the cases above, i got an error that element cannot be found. Is there something specific i need to do in order to select ui element according to content-desc? Note that I am using Appium



If you really have element with content description “pay now”, then

pay_now_button = driver.find_element_by_android_uiautomator('new UiSelector().description("pay now")')

should work…
Try descriptionContains…

pay_now_button = driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("pay now")')

Hi Kirill,

thanks for the reply. I don’t know what i did different but pay_now_button = driver.find_element_by_android_uiautomator(‘new UiSelector().description(“pay now”)’) now works.

One other issue i am having is trying to get the value in content-desc. So i have this code:

payment_success = driver.find_element_by_android_uiautomator(‘new UiSelector().description(“Payment Made”)’)

The first line works fine as I checked that it return the correct object. For the get_attribute call, I get an error that element could not be found using that search parameter.

Is this something not supported yet in Appium or the python client version (Appium_Python_Client-0.11-py3.3) i am using?


By value you mean text?
Try getText() method.

Hey Kirill,

The text field for this element is actually empty in this case so i need to get actual value of content-desc field. However, when i try payment_success.get_attribute(‘content-desc’), it gives me the error.


I finally found the solution to my get_attribute() issue. It seems I need to use get_attribute(“name”) in order to get the value in the content-desc field of element.

Follow this link!topic/appium-discuss/JJE8K4w7rng and read the post by Jonathan Lipps.

Thanks for your help!