首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TestStack.White和CCleaner

TestStack.White和CCleaner
EN

Stack Overflow用户
提问于 2016-03-11 20:47:29
回答 1查看 518关注 0票数 0

我对TestStack (White) UI自动化库非常陌生,在“挂钩”过程方面我遇到了一些问题。我想勾引CCleaner,但我一直

TestStack.White.AutomationException类型的未处理异常发生在TestStack.White.dll中 其他信息:无法在进程1156中找到带有标题Piriform CCleaner的窗口,等待30秒后:

我目前的代码是:

代码语言:javascript
复制
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";但这也引发了同样的例外。

我使用的是微软的“检查”,这就是它为我所吸引的东西(大图像):检查信息。你知道我在这里做错什么了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-15 13:53:21

问题是CCleaner作为WIN32应用程序是可见的。所以GetWindow()不起作用。您可以尝试以下代码:

代码语言:javascript
复制
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));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35949610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档