我试图使用下面的 xpath 获取所有元素的列表,但总是得到 1 作为大小。当我尝试 class,xpath 所有选项时,不确定我在这里做错了什么。我的目标是搜索后我们得到记录列表,我想循环遍历它们,到目前为止我已经尝试了几种选项,但没有运气让它工作。
尝试过的选项 -
//*[@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
硒代码-
(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">
我能够让它工作,在
<ul>
标签下我们有 <li>
元素,我试图从 <ul>
获取列表,这是错误的方法。为了解决这个问题,我首先将 <ul>
数据作为元素,然后从中提取所有 <li>
。
List<WebElement> elements = driver.findElements(By.className("WKRQ"));
WebElement primary = elements.get(1);
List<WebElement> li_All = primary.findElements(By.tagName("li"));