Page 1 of 1

getting ALL <li> children from div

Posted: Wed Sep 26, 2018 3:21 pm
by sstowe
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

Re: getting ALL <li> children from div

Posted: Wed Sep 26, 2018 3:40 pm
by odklizec
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.

Re: getting ALL <li> children from div

Posted: Wed Sep 26, 2018 5:36 pm
by sstowe
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.

Re: getting ALL <li> children from div

Posted: Wed Sep 26, 2018 6:13 pm
by sstowe
The code you gave will get LI direct children. I imagine it is not possible to get ALL li descendants?

Re: getting ALL <li> children from div

Posted: Wed Sep 26, 2018 7:04 pm
by odklizec
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.