如何使用 Selenium Java 获取元素 ArrayList 中的元素

How to get an element within an ArrayList of elements using Selenium Java

我在 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)

如何通过单独的机器解析得到每个实体的text/value?

外层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>

提前致谢。

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...));
   ...
}