getting ALL <li> children from div

Ask general questions here.
sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

getting ALL <li> children from div

Post by sstowe » Wed Sep 26, 2018 3:21 pm

I am writing a method to get all the li children of an element, usually a div at runtime. I want to pass in the repo item info and get all the li elements that are currently available. I would love to be able to get to all children, grandchildren and greats... for a given div of the div at runtime. Is this possible? Thanks

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

Re: getting ALL <li> children from div

Post by odklizec » Wed Sep 26, 2018 3:40 pm

Hi,

Please post a Ranorex snapshot (NOT screenshot!) of the element in question. Generally speaking, it should be possible to get the list of all ‘li’ elements, but without seeing, at very least, the snapshot, it’s hard to say what xpath should you use.

Basically, this xpath should return all li elements from given div...
//div//li
And this should help you with creating a list of litags...
IList<ranorex.litag> liList =
repo.path.to.divtag.elementInfo.CreateAdapters<ranorex.litag>();
BTW, please do not post the same question multiple times. It does not help with faster answer ;) 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

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: getting ALL <li> children from div

Post by sstowe » Wed Sep 26, 2018 5:36 pm

I will try that. Thanks. The thing about a snapshot is that I want to be able to do this for any div...
I did not realize I could not delete this one when I added the other which seemed a better place for it.

sstowe
Posts: 62
Joined: Thu May 31, 2018 2:26 pm

Re: getting ALL <li> children from div

Post by sstowe » Wed Sep 26, 2018 6:13 pm

The code you gave will get LI direct children. I imagine it is not possible to get ALL li descendants?

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

Re: getting ALL <li> children from div

Post by odklizec » Wed Sep 26, 2018 7:04 pm

The xpath I provided should return all li tags found after any div tag. Unfortunately, without snapshot, it’s hard to tell if the xpath is the optimal one. The code should simply create a list of adapters for all li tags returned by the xpath.
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