How to get the total size of the WebElements that has common class ?

Ranorex Studio, Spy, Recorder, and Driver.
Rishi1992
Posts: 5
Joined: Mon Jul 26, 2021 1:26 pm

How to get the total size of the WebElements that has common class ?

Post by Rishi1992 » Mon Jul 26, 2021 1:36 pm

Currently I'm using Ranorex Studio Trial Version. We have a web application & we want to automate the Test cases using Ranorex.

The problem I'm facing currently is, there are multiple items (or web elements) in the in the application dashboard that shares one common class (that means all these elements having the same class, but their other attributes are different from each other).

Now, I want to get the total size of these elements using user code. How to do that in Ranorex Studio ?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7429
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get the total size of the WebElements that has common class ?

Post by odklizec » Thu Jul 29, 2021 10:29 am

Hi,

I'm not exactly sure what is your goal? Could you please share more details about what exactly you want to achieve? What do you want to do with "size" of web element?

Ideally, please create and post a Ranorex snapshot and exact steps you want to perform, including some screenshots ;) Thanks.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Rishi1992
Posts: 5
Joined: Mon Jul 26, 2021 1:26 pm

Re: How to get the total size of the WebElements that has common class ?

Post by Rishi1992 » Mon Aug 02, 2021 12:26 pm

Thanks @odklizec for the reply.

Suppose there is a dropdown in my application. This dropdown is having thousands of options (e.g. Option A, Option B,.......Option n). I want to get the total number of options present in this dropdown list. How to do that programmatically (i.e. using C#) in Ranorex Studio ?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7429
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get the total size of the WebElements that has common class ?

Post by odklizec » Mon Aug 02, 2021 12:49 pm

Hi,

Thanks for the explanation. Now I understand ;) Well, it could be a very easy task, if the list of elements is entirely loaded. Or a pretty complicated one, if the list is lazy loaded (i.e. only the items visible in dropdown without scrolling are loaded in memory) ;)

Could you please post a Ranorex snapshot (NOT screenshot) of the dropdown in question?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Rishi1992
Posts: 5
Joined: Mon Jul 26, 2021 1:26 pm

Re: How to get the total size of the WebElements that has common class ?

Post by Rishi1992 » Mon Aug 02, 2021 1:04 pm

Hi @odklizec,

Thanks for the reply. Please find the attached snapshot.
Also one thing I want to add, when clicked on the said dropdown list, all the elements (i.e. entire options) are loaded at that time. :D
Attachments
dropdown.rxsnp
snapshot of the dropdown element
(67.72 KiB) Downloaded 103 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7429
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get the total size of the WebElements that has common class ?

Post by odklizec » Mon Aug 02, 2021 1:10 pm

Hi,

Thanks for the snapshot, but it's a snapshot of entire page! Please create one just for the dropdown.

Start tracking, press and hold F12 (to pause tracking), then click in dropdown to expand it, and then with mouse still above the expanded dropdown, release F12 and select the dropdown.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Rishi1992
Posts: 5
Joined: Mon Jul 26, 2021 1:26 pm

Re: How to get the total size of the WebElements that has common class ?

Post by Rishi1992 » Mon Aug 02, 2021 1:26 pm

Hi @odklizec,

Please find the updated snapshot. Hope this one helps.
Attachments
dropdown.rxsnp
snapshot of dropdown list
(90.63 KiB) Downloaded 105 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7429
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get the total size of the WebElements that has common class ?

Post by odklizec » Mon Aug 02, 2021 1:46 pm

Hi,

Yes, it's much better now.

So basically, this xpath returns all items of given dropdown:

Code: Select all

/dom[@domain='u01061loto01.tiretech.contiwan.com']//form//div[@class~'p-dropdown-panel']/?/?/ul[@class~'p-dropdown-items']/tag/li[@class~'p-dropdown-item']/span[@visible='true']
Just create a repo element with above xpath.
Now with this method, you should be able to get number of dropdown items:

Code: Select all

private void SelectMultipleCheckboxes(RepoItemInfo repoElement)
{
    // Create a list of adapters using the "Info" object
    IList<Ranorex.SpanTag> spanList = repoElement.CreateAdapters<Ranorex.SpanTag>()
    int spanListCount = spanList.Count;   
}
Simply create a UserCode with above method in Recording module of your choice and assign the repo element as a parameter. Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration