How can I check which element is selected?

Hi All,

I want to verify which language is selected eg: English and which is not so can you please tell me how can I very English is selected because while going through appium inspector I don’t see any difference in selected and non-selected elements in terms of attributes

Please refer to both the examples shown above and please let me know how can I achieve this.
Thanks :slight_smile:

1 Like

@Aleksei Do you have any thoughts on the same or could you please tag someone who can give me guidance in this? Thanks :slight_smile:

you need check attribute of image element

i don’t see any different option for the circle element


i hope you are referring to same thing.

Have you tried inspecting just the blue circle and seeing if appium is able to find it?

Yes I did but there was nothing. Is it because it is flutter app?

The purpose of the app has nothing to do with how it was developed. Now… If I were you, after executing the click I would get the text of the clicked element. It’s the most viable way

but how will get the text in this case? I don’t think so it is possible in this case

The returned text will be the clicked text, in this case “English”.

but in that case i think you should have testID for the selected item which should be unique so that we can get the of the selected item

It’s not complicated, in the English option you have the xpath as you can see in the print you put, you use the xpath to click and get the text. What programming language are you using?

TypeScript.
I am wondering if suppose I get the text using xpath for “English” (when the radio button is selected), text will return as “English”,
Now, if I click on “English” using xpath to deselect radio button, then again I will get the text it will also print “English”
What will be the difference?

Hi, I had some similar test cases.
In general, it is hard or even impossible in some cases to automate an app and make checks/validation without any ids or something that enables you to discern between different elements.
*assuming it is a commercial app.
In my opinion you should go to your android developers or do it yourself if you have the right permissions and change the behaviour of the app. I mainly use the selected/content-desc attributes.
I would go to the part in the code where a language is being selected (probably some listener) and when changing the language-cell button’s color I would set the cell’s selected attribute to be true.
as well, when another element is selected you need to remember to set the previous selected cell to false.
Then, you’ll be able to do something like so:
listElement.getCellByLanguage(“English”).isSelected();

Another way is that each time an element is being selected you’ll put its language value (e.g. english etc.) in the content-desc attribute of the list element (the parent element of all the language cells) so when you will select a language the content-desc of the list element will change accordingly.
Then, you’ll be able to do something like so:
listElement.getAttribute(“content-desc”).equals(“English”);

2 Likes

Can i do this in flutter code too because my application is in flutter so just wanted to confirm.

Don’t know about flutter specifically but I am sure that there is a way to implement the same thing there. At the end, Android will create a UI-element whether the code has been written in flutter or not. So, its attributes(e.g. selected, content-desc) will have the values you provided them through the code or their defaults.
You can just try and ask your developers. It should not be that complicated, those are native android element attributes.

1 Like

Thankyou for your input. :slight_smile:

Hi,
I also have the same problem. Any solution for this?
I tried with xpath but it’s not working
Ex: driver.findElement(By.xpath("//android.view.View[@content-desc=“Español Spanish”]")).click();
Is this can be fixed or any solution for this issue?

try instead:

driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().descriptionContains(\"Spanish\")"));

Thank you so much for your response… :slightly_smiling_face:. I’ll try that.

Not working…:frowning_face: