# Detect either if UIButton is selected or what its background image is

**URL:** <https://discuss.appium.io/t/detect-either-if-uibutton-is-selected-or-what-its-background-image-is/17582>\
**Category:** Support\
**Created:** [July 6, 2017, 2:25pm UTC](https://discuss.appium.io/t/detect-either-if-uibutton-is-selected-or-what-its-background-image-is/17582 "2017-07-06T14:25:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![h3dkandi](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/c67d28/32.png) [@h3dkandi](https://discuss.appium.io/u/h3dkandi)\
**Post date:** [July 6, 2017, 2:25pm UTC](https://discuss.appium.io/t/detect-either-if-uibutton-is-selected-or-what-its-background-image-is/17582/1 "2017-07-06T14:25:08Z")

</div>

I have a button that syncs my files. I need to wait out the sync if the sync is in progress. The only way I could think of doing it is by checking the changes that occur on the sync button.

When the sync button is clicked its `selected` property is set to true and the background image is changed and animated. What I believe I could do is detect either of them and wait for their state to change. However I don’t know how to get their state. At least for the `selected` property what I tries was:

```
var syncButton = driver.FindElementByAccessibilityId("Sync");
if (syncButton.GetAttribute("selected") == "true")
{
    Console.Write("Yes it is selected.");
 } 
else
{
    Console.Write("So sad, not selected.");
}

```

This code blows up because apparently there is no attribute with the name selected. `syncButton.Selected` doesn’t work as well.

The Accessibility Inspector shows the selected state under Traits but then again I don’t know if there is a way to check what the Traits of an element are.  
As for detecting what is the background image I don’t know even where to begin.

I am currently researching how to use xpath and uiautomation to see if they could be of any use.

---

<div class="post-metadata">

**Author:** ![Clark-Minor](https://discuss.appium.io/letter_avatar_proxy/v4/letter/c/fbc32d/32.png) [@Clark-Minor](https://discuss.appium.io/u/Clark-Minor)\
**Post date:** [October 20, 2020, 7:14pm UTC](https://discuss.appium.io/t/detect-either-if-uibutton-is-selected-or-what-its-background-image-is/17582/2 "2020-10-20T19:14:53Z")

</div>

Having the same issue on the iOS side which seems to correlate with a React Native upgrade. No longer able to use element.get\_attribute(‘value’) == ‘1’ or element.is\_selected() to determine if a button element is selected. I was wondering if you found any workarounds for this issue?
