0

我在 Java 中有一个数组列表,它给了我一个机器名称列表,如下所示:

By mNameUIList = By.xpath("//div[@class='machineblockdiv cursorpointer machinblockheight']//h4");
ArrayList<String> mUITextList = objUtilities.getElementsTextList(mNameUIList );
System.out.println(mUITextList );

这个 DIV 有 22 台机器。每台机器都有自己的个体实体,如机器名称、部件号等。我想遍历每张机器卡并获取其个体实体的值。

for (int i = 0; i < mUITextList .size(); i++) {
                
mUITextList.get(i)

在上面的代码中,我无法传递类似下面的内容

mUITextList.get(i).findElement(xpath of individual machine entity)

如何通过单个机器解析来获取每个实体的文本/值?

外部 HTML

<div _ngcontent-llu-c42="" class="machineblockdiv cursorpointer machinblockheight" style="height: 396px;"><h4 _ngcontent-llu-c42="">TC - 33</h4><div _ngcontent-llu-c42="" class="innerdiv1"><div _ngcontent-llu-c42=""><h3 _ngcontent-llu-c42="">53<span _ngcontent-llu-c42="" class="percentsign1 m-0">.52%</span></h3></div><div _ngcontent-llu-c42=""><h6 _ngcontent-llu-c42="" class="m-0">OEE</h6></div></div><div _ngcontent-llu-c42=""><div _ngcontent-llu-c42="" class="innerdiv1"><div _ngcontent-llu-c42="" class="mt-5"><label _ngcontent-llu-c42="" title="Part - 2409">Part - 2409</label><h6 _ngcontent-llu-c42="" class="m-0">Part Number</h6></div></div><div _ngcontent-llu-c42="" class="innerdiv2"><div _ngcontent-llu-c42=""><label _ngcontent-llu-c42="">105</label><h1 _ngcontent-llu-c42="" class="pull-right font-small"> 196 </h1></div><div _ngcontent-llu-c42=""><h6 _ngcontent-llu-c42="">Parts Produced</h6><h6 _ngcontent-llu-c42="" class="pull-right">Target</h6></div></div><app-progressbar _ngcontent-llu-c42="" _nghost-llu-c41=""><div _ngcontent-llu-c41="" class="progress progress-line"><div _ngcontent-llu-c41="" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="progress-bar green-prg-bar" style="width: 53.5714%;"><span _ngcontent-llu-c41="" class="sr-only"> 53.57142857142857 % Complete</span></div></div></app-progressbar></div><!----><!----><div _ngcontent-llu-c42=""><h5 _ngcontent-llu-c42="">Machine(s)  might needs some attention</h5><app-machine-statusbar _ngcontent-llu-c42="" _nghost-llu-c36=""><div _ngcontent-llu-c36="" class="indicatorwrapper"><span _ngcontent-llu-c36=""><span _ngcontent-llu-c36="" class="machine-indicators normal" title="TC-33"></span><!----><!----></span><!----></div></app-machine-statusbar></div><!----></div>

提前致谢。

4

1 回答 1

1
List<WebElement> elements = driver = findElements(By.xpath("//div[@class='machineblockdiv cursorpointer machinblockheight']//h4"));

for (WebElement element: elements) {
   WebElements childElement = element.findElement(By...));
   ...
}

或者

for (int i = 0; i < elements.size(); i++) {
   WebElement element = elements.get(i);
   WebElements childElement = element.findElement(By...));
   ...
}
于 2022-02-01T11:26:23.467 回答