How to find the child element in cutomizable drop-down(Urgent response required)

How to find the child element in cutomizable  drop-down(Urgent response required)

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

Default Asked on November 5, 2014 in Selenium WebDriver.
  • 3 Answer(s)

    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

    The solution to the query is appreciated.Well my question was to identify the nth sub-child option of any parent.
    I would add a real time example..
    consider the drop down lists something as mentioned below

    1.Clothing
    1.1.Men’s wear
    1.1.2 shirts
    1.1.3 Jeans
    1.2 women’s wear
    1.3 Kids wear
    2.electronics
    2.1 Mobiles
    2.2 Lpatops
    3.foot wears

    the above options “clothing”,”electronics” & “foot wears” is listed in drop down. Every options has “+” expand icon & clicking on it displays its sub-option.
    So the scenario is to identify “Jeans” option under “clothing”.The approach to identify has to be in such a way that it can identify any sub-option under parent list of drop down.

    Default Answered on November 6, 2014.
    Add Comment

    I meant to say:

    
    List <WebElement> clothes = driver.findElements(By.xpath("//div[@id='...']/ul"));
    
    int iLast = clothes.size();
    
    clothes.get(iLast).click();
    
    

    Regards,
    Lakshay Sharma

    Professor Answered on November 6, 2014.
    Add Comment
  • Your Answer

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