Forum Discussion
RickAlmeida
10 years agoModerator
Hello,
I found this forum post useful while helping another customer search for objects based on their automation id. Here's a sample script that works similar to findchild().
{
var window = Sys.Process("WpfApplication1.vshost").WPFObject("HwndSource: MainWindow", "MainWindow")
var MyAppDomain = "WpfApplication1.vshost.exe";
var MyAppProcess = Sys.Process("WpfApplication1.vshost");
myControl = FindByAutomationID (MyAppProcess, MyAppDomain, "button1aid", window, 5 ,false)
myControl.Click();
}
function FindByAutomationID ( objProcess, strAppDomain, strAutomationID, objSearchContainer, intSearchDepth, blCaseSensitive)
{
AutomationIdProperty = objProcess.AppDomain(strAppDomain).dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty
objarrChildren = objSearchContainer.FindAllChildren("Exists", "True", intSearchDepth);
objarrChildren = objarrChildren.toArray();
if (objarrChildren.length > 0)
{
for (ii = 0; ii < objarrChildren.length; ii++)
{
if (0 == aqString.Compare(strAutomationID, objarrChildren[ii].GetValue(AutomationIdProperty), blCaseSensitive))
{
Log.Message("Found control with automation id '" + strAutomationID + "': " + objarrChildren[ii].FullName);
return objarrChildren[ii];
}
}
}
Log.Warning("No control found with automation id: " + strAutomationID);
}
This script will successfully find a control defined by the following XAML in a WPF application:
<Button Content="Button1" Height="23" HorizontalAlignment="Left" Margin="252,134,0,0" AutomationProperties.AutomationId="button1AID" VerticalAlignment="Top" Width="75" Background="#E7FC0019" Foreground="#FF000700" BorderBrush="#FF070000" Click="Button_Click_1" >
Of course, you need to modify the window, MyAppProcess, and MyAppDomain variables to match your tested application.
Thanks,
Rick
SmartBear Customer Care
I found this forum post useful while helping another customer search for objects based on their automation id. Here's a sample script that works similar to findchild().
function foo ()
{
var window = Sys.Process("WpfApplication1.vshost").WPFObject("HwndSource: MainWindow", "MainWindow")
var MyAppDomain = "WpfApplication1.vshost.exe";
var MyAppProcess = Sys.Process("WpfApplication1.vshost");
myControl = FindByAutomationID (MyAppProcess, MyAppDomain, "button1aid", window, 5 ,false)
myControl.Click();
}
function FindByAutomationID ( objProcess, strAppDomain, strAutomationID, objSearchContainer, intSearchDepth, blCaseSensitive)
{
AutomationIdProperty = objProcess.AppDomain(strAppDomain).dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty
objarrChildren = objSearchContainer.FindAllChildren("Exists", "True", intSearchDepth);
objarrChildren = objarrChildren.toArray();
if (objarrChildren.length > 0)
{
for (ii = 0; ii < objarrChildren.length; ii++)
{
if (0 == aqString.Compare(strAutomationID, objarrChildren[ii].GetValue(AutomationIdProperty), blCaseSensitive))
{
Log.Message("Found control with automation id '" + strAutomationID + "': " + objarrChildren[ii].FullName);
return objarrChildren[ii];
}
}
}
Log.Warning("No control found with automation id: " + strAutomationID);
}
This script will successfully find a control defined by the following XAML in a WPF application:
<Button Content="Button1" Height="23" HorizontalAlignment="Left" Margin="252,134,0,0" AutomationProperties.AutomationId="button1AID" VerticalAlignment="Top" Width="75" Background="#E7FC0019" Foreground="#FF000700" BorderBrush="#FF070000" Click="Button_Click_1" >
Of course, you need to modify the window, MyAppProcess, and MyAppDomain variables to match your tested application.
Thanks,
Rick
SmartBear Customer Care
Related Content
- 4 months agoD0UG
- 5 years agolingling_chiang
- 5 years agoautomTest
Recent Discussions
- 3 days agoMW_Didata