FindSingle using a partial @accessiblename

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

FindSingle using a partial @accessiblename

Post by carsonw » Tue Sep 04, 2012 7:27 pm

Hi there - I have a combo box with a drop down of currencies.

We select the currency we want like this:

Code: Select all

ListItem listItem = comboBox.FindSingle<ListItem>("list/listitem[@accessiblename='"+ testField.Value + "']");
listItem.Select();
listItem.Click();
What I want to do is just pass in "CAD" for the accessible name, but the actual name is "CAD - Canada Dollar".

Is there a way we can do this? Thanks :)

Carson.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: FindSingle using a partial @accessiblename

Post by Ciege » Tue Sep 04, 2012 7:34 pm

You can use regular expressions...
See here: http://www.ranorex.com/support/user-gui ... xpath.html

Basically you'll need to change your equal sign "=" to a tilde "~" after the "@accessiblename". Then use the appropriate RegEx expression for what you want to do.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: FindSingle using a partial @accessiblename

Post by carsonw » Wed Sep 05, 2012 1:10 am

...obviously! It's funny how that totally escaped me since we have regular expressions all over the place in our repository - we just rarely search for objects in the code itself so it didn't even occur to me.

Just shows how it's good to have people to bounce things off of from time to time. Thanks! :)

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: FindSingle using a partial @accessiblename

Post by carsonw » Wed Sep 05, 2012 1:24 am

The only problem I run into now then, is that if I try to "FindChild" later I can only use the default label... not a regular expression in this case.

So this is what we're doing:

Code: Select all

public static Row GetDataRow(Dictionary<string, string> searchVaules, Table dataTable)
		{
			Row foundRow = null;
			foreach(Row iterationRow in dataTable.Rows)
			{
				bool valuesMatch = true;
				foreach(KeyValuePair<string, string> kvp in searchVaules)
				{
					if (kvp.Value != iterationRow.FindChild<Cell>(kvp.Key).Text)
					{
						valuesMatch = false;
						break;
					}
				}
				if (valuesMatch)
				{
					foundRow = iterationRow;
					break;
				}
			}
			return foundRow;
		}
But you can see I have to set the full, actual, text in this case. I tried using the regular expression earlier (so I could look for "CAD" instead of the whole thing) and that worked great. But now looking inside each cell for that value... I guess I could use "Find" instead of "FindChild", probably just as efficient and more flexible.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: FindSingle using a partial @accessiblename

Post by Support Team » Wed Sep 05, 2012 2:31 pm

Hi,

You can use each of the find methods mentioned on the following link: Row Class.

Regards,
Markus
Ranorex Support Team
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: FindSingle using a partial @accessiblename

Post by carsonw » Wed Sep 05, 2012 6:58 pm

Ahh yes - saw FindSingle in there, but it turns out to be much simpler than I thought. The column names are absolute so that's fine, and I just needed to the contains in the value. Really, what I needed was to walk away from it for a little while :)

It all works now though, in case it's useful to others, this is what it looked like in the end:

Setting:

Code: Select all

default:
					// Open combobox using property  
					comboBox.DropDownVisible = true; 
					  
					// Select list item with from DropDown list  
					ListItem listItem = comboBox.FindSingle<ListItem>("list/listitem[@accessiblename~'^"+ testField.Value + ".*']");
					listItem.Select();
					listItem.Click();
					Delay.Seconds(delayAfterFieldSetInSeconds);
					break;
Getting a row from the grid based on a partial match of the grid VALUE:

Code: Select all

public static Row GetDataRow(Dictionary<string, string> searchVaules, Table dataTable)
		{
			Row foundRow = null;
			foreach(Row iterationRow in dataTable.Rows)
			{
				bool valuesMatch = true;
				foreach(KeyValuePair<string, string> kvp in searchVaules)
				{
					Cell cellToVerify = iterationRow.FindChild<Cell>(kvp.Key);
					if (!cellToVerify.Text.Contains(kvp.Value))
					{
						valuesMatch = false;
						break;
					}
				}
				if (valuesMatch)
				{
					foundRow = iterationRow;
					break;
				}
			}
			return foundRow;
		}
Thanks again for the insights :)

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: FindSingle using a partial @accessiblename

Post by Ciege » Wed Sep 05, 2012 7:02 pm

Good stuff, thanks for sharing!
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...