我有3-4个Windows应用程序,它们以“WorkflowActionProcessor” 的名称运行,我想循环并模拟其中每个按钮的单击。
为了模拟点击,我使用了teststack.white .NET
库。
下面的代码为我提供了仅一个应用程序的详细信息:
TestStack.White.Application application = TestStack.White.Application.Attach("WorkflowActionProcessor");
Window window = application.GetWindow("Work Flow Action Processor", InitializeOption.NoCache);
SearchCriteria searchCriteria = SearchCriteria.ByText("Stop Execution");
TestStack.White.UIItems.Button button = window.Get<TestStack.White.UIItems.Button>(searchCriteria);
button.Click();
但是,如何将所有应用程序保存在一个可枚举的文件中并进行处理。
最佳答案
您可以在应用程序上使用GetWindows函数。
TestStack.White.Application application = TestStack.White.Application.Attach("WorkflowActionProcessor");
Window windows = application.GetWindows();
foreach(var window in windows) {
SearchCriteria searchCriteria = SearchCriteria.ByText("Stop Execution");
TestStack.White.UIItems.Button button = window.Get<TestStack.White.UIItems.Button>(searchCriteria);
button.Click();
}
也刚刚意识到我认为您的意思是您有4个相同名称的相同应用程序。没有白色的方法可以获取特定名称的所有应用程序。为此,您需要启动该过程4次,然后再附加到每个过程中。
var startInfo = new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = false,
FileName = "your.exe",
Arguments = "your arguements",
};
List<TestStack.White.Application> applications = new List<TestStack.White.Application>();
for(int applicationCounter = 0, applicationCounter < 3; applicationCounter++) {
TestStack.White.Application application = TestStack.White.Application.AttachOrLaunch(startInfo);
applications.Add(application);
}
List<Window> windows = new List<Window>();
foreach(var application in applications)
{
windows.AddRange(application.GetWindows());
}
foreach(var window in windows)
{
SearchCriteria searchCriteria = SearchCriteria.ByText("Stop Execution");
TestStack.White.UIItems.Button button = window.Get<TestStack.White.UIItems.Button>(searchCriteria);
button.Click();
}
我尚未运行此代码,因此可能需要花上几周的时间,但总体思路是从自动化应用程序中多次启动该应用程序,以便每个应用程序都有一个应用程序对象,因为attach始终会附加到该应用程序上。首先使用您指定的名称进行处理。
关于.net - 通过应用程序名称获取所有应用程序-TestStack.White .NET,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39694487/