我对TestStack (White) UI自动化库非常陌生,在“挂钩”过程方面我遇到了一些问题。我想勾引CCleaner,但我一直
TestStack.White.AutomationException类型的未处理异常发生在TestStack.White.dll中 其他信息:无法在进程1156中找到带有标题Piriform CCleaner的窗口,等待30秒后:
我目前的代码是:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems.Finders;
using TestStack.White.InputDevices;
using TestStack.White.UIItems.WindowItems;
namespace NightWipe
{
class Program
{
private const string ExeSourceFile = @"C:\Program Files\CCleaner\CCleaner.exe";
private static TestStack.White.Application _application;
private static TestStack.White.UIItems.WindowItems.Window _mainWindow;
static void Main(string[] args)
{
clean();
}
public static string clean()
{
var psi = new ProcessStartInfo(ExeSourceFile);
_application = TestStack.White.Application.AttachOrLaunch(psi);
_mainWindow = _application.GetWindow("Piriform CCleaner");
_mainWindow.WaitWhileBusy();
return "";
}
}
}我认为这可能是进程的名称,因为CCleaner启动了另一个进程(而不是CCleaner.exe),但是CCleaner64.exe (见过这里 ),我可以假设它适用于64位操作系统?无论如何,我尝试了一些名称,包括:"CCleaner“、"CCleaner64";但这也引发了同样的例外。
我使用的是微软的“检查”,这就是它为我所吸引的东西(大图像):检查信息。你知道我在这里做错什么了吗?
发布于 2016-03-15 13:53:21
问题是CCleaner作为WIN32应用程序是可见的。所以GetWindow()不起作用。您可以尝试以下代码:
public void CCleanerSample()
{
var application = Application.AttachOrLaunch(new ProcessStartInfo(@"C:\Program Files\CCleaner\CCleaner.exe"));
AutomationElement ccleanerAutomationElement = null;
Console.Write("Waiting till WIN32 app is launching");
while (ccleanerAutomationElement == null)
{
ccleanerAutomationElement = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "Piriform CCleaner"));
Thread.Sleep(1000);
Console.Write(".");
}
Console.WriteLine(" Done");
var mainWindow = new Win32Window(ccleanerAutomationElement, WindowFactory.Desktop, InitializeOption.NoCache,
new WindowSession(application.ApplicationSession, InitializeOption.NoCache));
}https://stackoverflow.com/questions/35949610
复制相似问题