New Ranks & Badges For The Community!
Notice something different? The ranks and associated badges have gone "Star Fleet". See what they all mean HERE
Highlighted
Absent Member.
Absent Member.
1524 views

Find all Xpath with wildcard and add to an array

Jump to solution

Hello everyone,


I am using Mainframe and Rumba,

I am trying to find all RumbaLabels

 

This is my absolute path for a textfield with data.
desktop.<RumbaTextField>find("(\"Terminal - Micro Focus Rumba.\")//RumbaScreen//RumbaLabel[@caption='D-12345']"

 

this is what I came up with so far 

System.out.println(desktop.<RumbaScreen>find("Terminal - Micro Focus Rumba.Screen").find("//RumbaLabel[@caption='D-******']").getText());


I guess I only need to implement a for loop.

Now I need to fetch all "D-XXXXX" elements to an array/list


Could someone help me out?

Regards

Xsi

Tags (4)
0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert
Hi Xsi

If you want to get a list of all RumbaLabels in your application, you could try the following and modify as required depending on your requirements.

@Test
public void findAllLabels() {


List<TestObject> iList = new ArrayList<TestObject>();

iList = desktop.findAll("//RumbaLabel");

for(TestObject label: iList) {

System.out.println("Label Locator:" + label.generateLocator());
System.out.println("Label caption:" + label.getProperty("caption"));
}


}
Senior (Specialist) Technical Support Engineer
ADM | Functional Testing | Mobile Center
Micro Focus

View solution in original post

Highlighted
Micro Focus Expert
Micro Focus Expert
Import this instead :

import java.util.List;
Senior (Specialist) Technical Support Engineer
ADM | Functional Testing | Mobile Center
Micro Focus

View solution in original post

0 Likes
7 Replies
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor
Try something like this:
Dim textFields As IList(Of RumbaTextField) = desktop.<RumbaTextField>FindAll("(\"Terminal - Micro Focus Rumba.\")//RumbaScreen//RumbaLabel[@caption='D-*']"
for each txtfield in textFields
' do something
next
0 Likes
Highlighted
Absent Member.
Absent Member.

Could you provide me with an example in java


This is what I came up with so far:

System.out.println(desktop.<RumbaScreen>find("Terminal - Micro Focus Rumba.Screen").findAll("//RumbaLabel[@caption='D-******']").get(2).getText());

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert
Hi Xsi

If you want to get a list of all RumbaLabels in your application, you could try the following and modify as required depending on your requirements.

@Test
public void findAllLabels() {


List<TestObject> iList = new ArrayList<TestObject>();

iList = desktop.findAll("//RumbaLabel");

for(TestObject label: iList) {

System.out.println("Label Locator:" + label.generateLocator());
System.out.println("Label caption:" + label.getProperty("caption"));
}


}
Senior (Specialist) Technical Support Engineer
ADM | Functional Testing | Mobile Center
Micro Focus

View solution in original post

Highlighted
Absent Member.
Absent Member.

I get this issue

 

How do I solve that?

 

I have imported:

import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;

 

Thank you in advance

Regards

Xsi

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert
Import this instead :

import java.util.List;
Senior (Specialist) Technical Support Engineer
ADM | Functional Testing | Mobile Center
Micro Focus

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.
how do I add instead all strings to a regular ArrayList<String>myArr=new ArrayList<String>();?
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert
Hi Xsi

You can just use the .add() method to add the required to your ArrayList. Make sure to call .toString().

ArrayList<String> myArr = new ArrayList<String>();

List<TestObject> iList = new ArrayList<TestObject>();

iList = desktop.findAll("//RumbaLabel");

for(TestObject label: iList) {

//add each TestObject as a string to ArrayList
myArr.add(label.toString());

}
//print ArrayList
for(String item: myArr) {
System.out.println(item);
}
Senior (Specialist) Technical Support Engineer
ADM | Functional Testing | Mobile Center
Micro Focus
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.