Iterate through 2 dynamic lists and compare text values

Class library usage, coding and language questions.
cataeldo
Posts: 1
Joined: Tue Jul 31, 2018 10:15 am

Iterate through 2 dynamic lists and compare text values

Post by cataeldo » Tue Jul 31, 2018 10:52 am

Hello, I am not a developer but I am trying to figure out how to do the following:

I am automating a desktop application, and I have a container with 2 dynamic lists (Base on certain device that I have plugged in to my application, the number of rows in the list might vary). I need to iterate through all the existing rows (rows with values) and compare one specific parameter with the other list's parameter.
In the image, I need to compare that each value inside the red circle matches each value of the green circle, however, the number of rows is dynamic and it can vary.

Image

Why I am trying to do is something like (But I am just trying things that I have read in other posts), but this is not doing anything:
 IList<Ranorex.Cell>myListDriver = repo.VerifyDriverSetting.ListViewDriver.TextViewDriver.Find<Ranorex.Cell>("/form[@title='Verify Driver Setting']//container[@name='driverDetailsView']//list[@name='listView']");
            IList<Ranorex.Cell>myListProfile = repo.VerifyDriverSetting.ListViewProfile.TextViewProfile.Find<Ranorex.Cell>("/form[@title='Verify Driver Setting']//element[@name='splitView']/container[@name='profileDetailsView']/?/?/container[@name='paramsTree']/list[@name='listView']");
           
           	foreach(Cell cell in myListProfile)
           	{
           		foreach(Cell celda in myListDriver)
           		 {
           	

           		string value1 = repo.VerifyDriverSetting.ListViewProfile.TextViewProfile.Caption;
           		string value2 = repo.VerifyDriverSetting.ListViewDriver.TextViewDriver.Caption;
           		
           		if(value1==value2)
           			{
           		Report.Log(ReportLevel.Info, "Value Parameter profile matches the driver parameter");
           		
           			}
           		else 
           			{
           			Report.Log(ReportLevel.Info, "Value Parameter profile does not match the driver parameter");
           			}
           		
           		} 

Please see my snapshot.

Please any idea and help for this newbie :(
Thanks
Attachments
SnapshotLists.png
SnapshotLists.png (25.57 KiB) Viewed 153 times

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Iterate through 2 dynamic lists and compare text values

Post by McTurtle » Thu Aug 02, 2018 3:26 pm

Hi cataeldo,

What you are doing is comparing every cell in column 1 with every cell in column 2. This will give you 6 successes and 30 failures as you actually have 36 comparisons. Only when the cells with the same indexes are compared, then the validation has a chance to succeed. You need to change the foreach part of your code to be something like this:
int k=0;
			
			foreach(Cell cell in myListProfile)
			{
				if(cell.Caption==myListDriver[k].Caption)
				{
					Report.Info(string.Format("Same index in list has same value: {0} == {1}",cell.Text,myListDriver[k].Caption));
				}
				else
				{
					Report.Info(string.Format("Samle index in list does not have same value. {0} == {1}",cell.Text,myListDriver[k].Caption));
				}
				k++;
			}
This will also work only if the lists are not empty. Please debug your code and check if the lists are actually populated with cells.

Regards,
McTurtle