简体   繁体   中英

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

I have an array list in Java that gives me a list of machine names as below:

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

This DIV has 22 machines. Each machine has its own individual entities like machine name, part number etc. I want to loop through each machine card and get the value of its individual entity.

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

In above code I am unable to pass something like below

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

How do I get the text/value of each entity by parsing through individual machine?

Thanks in advance.

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

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

or

for (int i = 0; i < elements.size(); i++) {
   WebElement element = elements.get(i);
   WebElements childElement = element.findElement(By...));
   ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM