How do you select a child element that is a Cell that has a specific value? When I use Ranorex Spy the current value is displayed. I assume there is some way to select the specific cell.
BTW - This is a really cool product, good job.
How to Select a Cell with a Value
Working with grids
Yeah, I think it would be great to see some sample code on how to handle grids in general. How to retrieve and post data to specific cells and how to search cells, rows and columns for specific data... if any or all of that is possible.
The following sample demonstrates how to read and write cell elements of a grid view.
This code works with the Microsoft DataGridView Control sample.
You can download the sample application from:
http://msdn2.microsoft.com/en-us/library/1x64c23x.aspx
You cannot search a cell by value in V1.1.0, but you will be able to search an element by value in the next version.
You will be able to search the sub-tree of the element and return the children that match the specified value and search mode. You can also use regular expression.
Please contact us if you want to test the function Element.FindChildValue.
We can send you a trial of the next version.
Jenö
Ranorex Team
This code works with the Microsoft DataGridView Control sample.
You can download the sample application from:
http://msdn2.microsoft.com/en-us/library/1x64c23x.aspx
Code: Select all
class Program
{
static public void DumpElementTree(Element element, int level)
{
level++;
int childCount = element.GetChildCount;
for (int index = 0; index < childCount && index < 10; index++)
{
Element child = element.GetChild(index);
if( child == null )
continue;
string space = new string(' ', 2*level);
Console.WriteLine("{0}Role={1} Name={2} Value={3}",
space, child.Role.ToString(), child.Name, child.Value);
DumpElementTree(child,level);
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
int ret;
Application.SleepTime = 10;
//-----------------------------------------
// F O R M search and test
//-----------------------------------------
Form form = Application.FindFormTitle("Customer Order Viewer");
if (form == null)
{
Console.WriteLine("Cannot find application \"Customer Order Viewer\"");
return 1;
}
Console.WriteLine("Application found");
form.Activate();
//-----------------------------------------
// Find G R I D V I E W
//-----------------------------------------
Control dataGridView1 = form.FindControlName("dataGridView1");
if (dataGridView1 == null)
{
Console.WriteLine("ERROR: dataGridView1 not found ");
return 1;
}
// Dump out some elements
DumpElementTree(dataGridView1.Element, 0);
// Find the element by name
Element contactRow7 = dataGridView1.Element.FindChild(Role.Cell, "Contact Name Row 7");
if (contactRow7 != null)
contactRow7.Value = "Ranorex";
// Find cell by value
Element pedro = dataGridView1.Element.FindChildValue("Pedro Afonso",SearchMatchMode.MatchExact);
if ( pedro != null )
{
Console.WriteLine(" Name={0} Value={1}", pedro.Name, pedro.Value);
Mouse.MoveToElement(pedro);
}
Console.WriteLine("\nTEST PASSED\n");
return 0;
}
}
Code: Select all
dataGridView1.Element.FindChildValue("Pedro Afonso",SearchMatchMode.MatchExact);
Please contact us if you want to test the function Element.FindChildValue.
We can send you a trial of the next version.
Jenö
Ranorex Team