我的appln上有15个小部件(很少添加数据,其他未添加data-html)。我必须识别span内容(如果存在)并将其与通过硒的db值进行比较-两者都在同一个web元素下。如果不存在span标签,则需要单独提取段落标签的值。所有这些都是动态窗口小部件,并根据下拉选择填充值。所有这些小部件都将始终处于相同的顺序,我需要知道span元素属于哪个小部件才能将其与查询匹配。有人可以帮忙吗?
<percentage-widget _nghost-c22="">
<div _ngcontent-c22="" class="widget-row">
<!----><div _ngcontent-c22="" class="widget-col">
<!----><div _ngcontent-c22="">
<div _ngcontent-c22="" class="default-widget">
<div _ngcontent-c22="" class="support-block__img">
<img _ngcontent-c22 src="assets/img/shared/widgets/F1_color.svg">
<div _ngcontent-c22="" class="mask" style="height: 5.17%;">
<img _ngcontent-c22="" src="/F1_bw.svg">
</div>
</div>
<div _ngcontent-c22="" class="people-count">
<span _ngcontent-c22="">95% </span>
</div>
<div _ngcontent-c22="" class="default-widget-info">
<p _ngcontent-c22="">living area </p>
<div _ngcontent-c22="" class="info-count">57</div>
</div>
</div>
<div _ngcontent-c22="" class="total-row-wrap">
<div _ngcontent-c22="" class="total-row">
<p _ngcontent-c22="">57 </p>
</div>
</div>
</div>
<!---->
</div>
</div>
</percentage-widget>
<percentage-widget _nghost-c22="">
<div _ngcontent-c22="" class="widget-row">
<!----><div _ngcontent-c22="" class="widget-col">
<!---->
<!----><div _ngcontent-c22="">
<div _ngcontent-c22="" class="default-widget">
<div _ngcontent-c22="" class="support-block__img">
<img _ngcontent-c22="" src="a/F5_bw.svg">
</div>
<!---->
<div _ngcontent-c22="" class="default-widget-info">
<p _ngcontent-c22="">support </p>
</div>
</div>
<div _ngcontent-c22="" class="total-row-wrap">
<div _ngcontent-c22="" class="total-row">
<p _ngcontent-c22="">No Data</p>
</div>
</div>
</div>
</div>
</div>
</percentage-widget>
这是我的代码:
List allElements =driver.findElements(By.xpath("//percentage- widget//div[@class='default-widget']"));
WebElement parent = allElements.get(1);
List<WebElement> children = parent.findElements(By.xpath("//div"));
String expectedClass = "widget-people-count";
boolean checkClass = false;
for (WebElement child : children)
{
if (children.contains(expectedClass)) {
checkClass = true;
}
if (checkClass) {
System.out
.println("We have at least one child has expected class: "
+ parent.getText());
String Count = parent.findElement(By.xpath("//div[@class='default-widget-info']//p")).getText();
System.out.println( Count);
}
else
System.out.println("We don't have any child span expected class: " + expectedClass);
基本上,我想识别每个小部件中的所有值,并通过查询每个Web元素值来将其与后端进行比较。.没有数据小部件将不包含span标记。.仅包含
标签。请以正确的方法帮助我。