skip to Main Content

I am trying to get list of all elements using below xpath, but always getting 1 as size. Not sure what i am doing wrong here as i tried class,xpath all options. My goal is after search we get list of records and i want loop through them, i have tried several options so far but didn’t had luck to get it working.

Options Tried –

//*[@id="wd-TemplatedList-6$62784"]
//*[@id="wd-SearchResultsPanel"]/div[3]
//*[@id="wd-SearchResultsPanel"]
//*[@id="wd-SearchResultsPanel"]/div[3]
//*[@id="wd-SearchResultsPanel"]/div[3]
//*[@id="wd-TemplatedList-6$62784"]/ul
//*[@id='wd-TemplatedList-6$62784']
//*[@id='wd-SearchResultsPanel']/div[3]
//*[@id='wd-TemplatedList-6$62784']
//*[@id='wd-TemplatedList-6$62784']/ul
//*[@id="promptOption-gwt-uid-97"]
//*[@id='wd-CompositeWidget-6$62782']
WNKQ WOLQ

/html/body/div[1]/div/div[6]/div[2]/div[1]/div[2]/div/input
//*[@id="wd-searchInput"]/input

Selenium Code –

(driver.findElements(By.className("WNKQ WOLQ"))).size()
List<WebElement> elements = driver.findElements(By.xpath("//*[@id='wd-TemplatedList-6$62784']/ul"));

HTML –

   <div class="WNKQ WOLQ" style="" xpath="1">
       <h3 class="WMKQ">All of Data</h3>
       <div id="wd-TemplatedList-6$62784" data-metadata-id="6$62784" class="WIAB">
          <span class="WDXV" aria-hidden="true" style="display: none;"><button class="WOSD WPXO" data-automation-id="paginationPrevious" role="button" title="Previous" type="button" tabindex="0"><img src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/FF8AA1765E87EC5EE29C081C99FAC994.cache.svg" class="gwt-Image WHXV" alt=""></button><span class="gwt-InlineLabel WFXV" data-automation-id="paginationText"></span><button class="WOSD WPXO" data-automation-id="paginationNext" role="button" title="Next" type="button" tabindex="0"><img src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/0E3EC1EBE120F13E140528EC9B393D2A.cache.svg" class="gwt-Image WCXV" alt=""></button></span>
          <ul class="WKRQ" data-automation-id="templatedList">
             <li class="WP3F WIAB WG5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="150f41534ec84b858eb1d082b8f25a10" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$3519">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-86" data-automation-label="% zeroda Movement by Gender" title="% zeroda Movement by Gender" aria-label="% zeroda Movement by Gender" role="link" tabindex="0">% zeroda Movement by Gender</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions % zeroda Movement by Gender" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WG5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="9d38c4b55f6944f6afa6423e393e9ca2" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$3520">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-87" data-automation-label="% zeroda Movement by Race/ Ethnicity" title="% zeroda Movement by Race/ Ethnicity" aria-label="% zeroda Movement by Race/ Ethnicity" role="link" tabindex="0">% zeroda Movement by Race/ Ethnicity</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions % zeroda Movement by Race/ Ethnicity" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WF5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="7b24ce7df35f45ebaf2b34c8c6220f72" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$3447">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-88" data-automation-label="zeroda Belonging Council Members" title="zeroda Belonging Council Members" aria-label="zeroda Belonging Council Members" role="link" tabindex="0">zeroda Belonging Council Members</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions zeroda Belonging Council Members" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <span class="gwt-InlineLabel WD5F WC4F" title="A report of zerodas who are members of the zeroda Belonging Councils." id="gwt-uid-89" data-automation-id="compositeSubHeaderOne">A report of zerodas who are members of the zeroda Belonging Councils.</span>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WG5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="f7e273eff015417b9d28a411307f419d" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$778">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-90" data-automation-label="zeroda Benefit Annual Rate Source" title="zeroda Benefit Annual Rate Source" aria-label="zeroda Benefit Annual Rate Source" role="link" tabindex="0">zeroda Benefit Annual Rate Source</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions zeroda Benefit Annual Rate Source" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WF5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="83e38a7853fe4651846fdb6985b772c7" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$1001">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-91" data-automation-label="zeroda Benefit Credit Report" title="zeroda Benefit Credit Report" aria-label="zeroda Benefit Credit Report" role="link" tabindex="0">zeroda Benefit Credit Report</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions zeroda Benefit Credit Report" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <span class="gwt-InlineLabel WD5F WC4F" title="Returns zerodas with Benefit Flex Credits
                      Prompts by Country.
                      Countries with Benefit Credits: USA, Canada, Singapore" id="gwt-uid-92" data-automation-id="compositeSubHeaderOne">Returns zerodas with Benefit Flex Credits
                   Prompts by Country.
                   Countries with Benefit Credits: USA, Canada, Singapore</span>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WF5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="1116b283f40f4011b8142e841f964d58" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$1791">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-93" data-automation-label="zeroda Benefit Credits" title="zeroda Benefit Credits" aria-label="zeroda Benefit Credits" role="link" tabindex="0">zeroda Benefit Credits</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions zeroda Benefit Credits" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <span class="gwt-InlineLabel WD5F WC4F" title="Returns zerodas with Benefit Flex Credits
                      Prompts by Country.
                      Countries with Benefit Credits: USA, Canada, Singapore" id="gwt-uid-94" data-automation-id="compositeSubHeaderOne">Returns zerodas with Benefit Flex Credits
                   Prompts by Country.
                   Countries with Benefit Credits: USA, Canada, Singapore</span>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WF5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="d14356916d4241938e7c0682074ab666" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$845">
                                        <ul class="WPEP"></ul>
                                        <div class="gwt-Label WOFP WHEP" data-automation-id="promptOption" id="promptOption-gwt-uid-95" data-automation-label="zeroda Benefit Elections - Current vs. Previous" title="zeroda Benefit Elections - Current vs. Previous" aria-label="zeroda Benefit Elections - Current vs. Previous" role="link" tabindex="0">zeroda Benefit Elections - Current vs. Previous</div>
                                        <ul class="WPEP WFFP" role="presentation">
                                           <li class="WMFP" role="presentation"><img class="gwt-Image WIWQ WJHS WDJS WPXO WAFP" src="https://zeroda.zerodacdn.com/zeroda/asset/ui-html/update/zerodaApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt="" data-automation-id="RELATED_TASK_charm" data-uxi-element-id="related-actions-charm" data-uxi-element-uniqueid="true" role="button" aria-label="Related Actions zeroda Benefit Elections - Current vs. Previous" tabindex="0"></li>
                                        </ul>
                                     </div>
                                  </div>
                               </div>
                            </li>
                         </ul>
                      </div>
                   </div>
                   <span class="gwt-InlineLabel WD5F WC4F" title="Returns all Benefit Elections for a worker, past and present. 
                      Prompts by Worker" id="gwt-uid-96" data-automation-id="compositeSubHeaderOne">Returns all Benefit Elections for a worker, past and present. 
                   Prompts by Worker</span>
                   <div class="wd-Text WEW2 WJW2 WIAB WA5F WC4F" data-automation-id="compositeSubHeaderTwo" id="56$284555" data-metadata-id="56$284555" dir="ltr">Report Definition</div>
                </div>
             </li>
             <li class="WP3F WIAB WF5F" data-automation-id="compositeContainer" role="listitem" id="wd-CompositeWidget-6$62782" data-metadata-id="6$62782">
                <div class="WA4F WO3F">
                   <div class="WOC- WGB- WIAB WPD- WND- WG4F WC4F" data-automation-id="compositeHeader" id="56$284553" data-metadata-id="56$284553">
                      <div class="WDD-">
                         <ul tabindex="-2" class="WPOR WCD-" role="presentation" data-automation-id="selectedItemList">
                            <li class="WDPR" role="presentation">
                               <div class="WJOR WLNR WCPR" tabindex="-2" id="86f24f58f60740698248354a940dfeab" data-automation-id="menuItem" role="presentation">
                                  <div class="WKOR">
                                     <div class="WNFP WHEP WBFP" data-automation-id="selectedItem_1422$397">

2

Answers


  1. Chosen as BEST ANSWER

    I was able to get it working, under the <ul> tag we have <li> elements, i was trying to get list from <ul> which was wrong approach. To solve this first i took <ul> data as element and then from that i pulled all the <li>.

    List<WebElement> elements = driver.findElements(By.className("WKRQ"));
    WebElement primary = elements.get(1);
    List<WebElement> li_All = primary.findElements(By.tagName("li"));
    

  2. I see you posted an answer but there is a more efficient way to get the elements you want… it only scrapes the page once instead of twice.

    List<WebElement> results = driver.findElements(By.cssSelector("ul.WKRQ > li"));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search