RE: How to find the child element in cutomizable drop-down

RE: How to find the child element in cutomizable  drop-down

Consider on clicking drop down,options are listed out.Now clicking on those options displays its child option &  again on clicking on child option opens sub-child option.this could go to nth level.
The concern is that the parent options listed in drop down can have any no of child.
For ex a parent option can have 2 child option & another can have 5 child option.

“+” icon near option represents expand
“|_>” down arrow indicates there is no child option(i.e. final child option)

Note:
For more clarification go through the attachment.
I wish to find element 13 under parent option named 11.
The option value is not unique.Let me know the approach  in such away that any child option can be clicked which is under any parent option in drop down.

Html coding is as mentioned below

<div class=”row_desc>

<div class=”item_hierarchy active>
<div class=”item_hierarchy_select>
<div class=”item_hierarchy_sec style=”display: block;>
<div class=”element_block>
<div class=”treemenu_sec jstree jstree-0 jstree-classic jstree-focused>
<ul class=”jstree-no-dots>
<li id=”” class=”jstree-leaf>
<li id=”757 class=”jstree-closed>
<li id=”760 class=”jstree-closed>
<li id=”808 class=”jstree-leaf>
<li id=”1753 class=”jstree-leaf>
<li id=”1754 class=”jstree-leaf>
<li id=”1776 class=”jstree-open>
<ins class=”jstree-icon/>
<a class=”” href=”#>
<ul id=”myid style=””>
<li id=”1777 class=”jstree-last jstree-closed>
<ins class=”jstree-icon/>
<a class=”jstree-hovered href=”#>
<ins class=”jstree-icon/>
13
</a>
<ul id=”myid>
<li id=”1778 class=”jstree-last jstree-leaf>
<ins class=”jstree-icon/>
<a href=”#>
<ins class=”jstree-icon/>
1
</a>
</li>
</ul>
</li>
</ul>
</li>
<li id=”1755 class=”jstree-closed>
<li id=”1779 class=”jstree-closed>
<li id=”755 class=”jstree-closed>
<li id=”740 class=”jstree-closed>

 

Please let me know your valuable answers on this scenario.Thank you  in advance

praku Default Asked on November 5, 2014 in Selenium WebDriver.
3 Answers

Hi Praku,

Your HTMl code says that it is a list of elements, so you can get the number of Child element like this:


List <WebElement> allElements = driver.findElements(By.xpath("//div[@id='...']/ul/li"));

int iSize = allElements.size();

for (WebElement element: allElements) {

System.out.println(element.getText());

}

Once you get the size and the name of the child element, i think then you would be able to move forward with your logic.

Regards,
Lakshay Sharma

Professor Answered on November 5, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.