TestProject Forum
Powered by leading experts in the test automation community

How to get text of each item in a list

On my application there are some items are being listed like
–>aa
–>bb
–>cc

its not a dropdown, it comes as xpath div//h3[@class=‘ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons’]​

Count of abpve xpath result 3 items

How can I get the count of all these elements and text during recording?

Also I have to select random value in next steps?

Also can we add steps based on decision…like if we dont have any element present here then I have to click some other link other wise continue on same.

Hi, thanks for reaching out.
You can get the count of the element in the recorder using the count elements by locator action.

For random values, if you mean by selecting on of the random values in the list,
you can use the Random number in range action m the Min action will be the minimum items in the list while the ma will be the number you gotten before, the amount of elements found with the locator.

There you can select one of the items in the list with the random index generated and get its value.

For the last question, yes you can.
You can decide the flow of your test with If-else logic even tho it is easier in recorded test.
Read this article to know how to do this in the recorder: https://intercom.help/testprojectio/en/articles/3788681-if-else-logic

Regards, Ran.

Thanks for reply…

How I get get text of all element e.g. //h3[@class=‘ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons’]​ returns 3 element and I have to get and store text for each element…
Currently its giving me text of only first element
I am doing like

Also can I use loops using recording actions?

When you use the xpath //h3[@class=‘ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons’] it returns an array of all items corresponding to that xpath, so you can use array notations like so

//h3[@class=‘ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons’][0] will give you the first element, 1 the 2nd and so on. ( Arrays start from 0)
After that, you can use the GetText action on each of those for their text values.

Regards, Ran.

But if I have 100 items, so I can’t write same line for 100 times to get text of every element.

Also the size is not static, it could be dynamic…so Is there any other way I can loop through all the returned element and get text of each element

Like i said above, then count elements will give you the upper bound of how many elements you need to iterate over.

If you want to go over ALL the elements then it will take multiple steps.
One to get the element, one to get the text and one to move the index forward ( Like a for loop )
So for your use case, I would suggest doing this in a coded test with a simple loop.

If you need any help implementing it, just let me know.

I haven’t go through coded test yet, exploring recorder only…

Is coded test will added in recorded script?

Yes it would be grateful if you can help over call or meeting

You can generate the code of the recorded test and extend it, adding the loop like you need.
Then upload it back to the platform.

Sure you can reach out in the chat, and I will send you an zoom link.