首页 新闻 会员 周边 捐助

使用UI Automation编写代码自动修复,卸载VS2010,InvokePattern无效

0
悬赏园豆:10 [已关闭问题]

Console.WriteLine("launch VSTS");
      Process p = Process.Start(@"D:\vs_ultimateweb.exe");
      AutomationElement Desktop = AutomationElement.RootElement;
      Thread.Sleep(500);
      AutomationElement AuDev10 = null;
      // AuDev10 is 欢迎页

      Thread.Sleep(5000);
      while (AuDev10 == null)
      {
        AuDev10 = Desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Microsoft Visual Studio 2010 Ultimate"));
      }
      AutomationElementCollection ControlList = AuDev10.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
      ///[0] is "< Previous"
      ///[1] is "Next >"
      ///[2] is "Cancel"
      ///[3] is "最小化"
      ///[4] is "最大化"
      ///[5] is "关闭"
      Console.WriteLine("Click the next button");
      Thread.Sleep(3000);
      AutomationElement NextTar = ControlList[1];  //点击下一步
      while (true)
      {
        if (NextTar.Current.IsEnabled)
        {
          InvokePattern Iprevious = (InvokePattern)NextTar.GetCurrentPattern(InvokePattern.Pattern);
          Iprevious.Invoke(); //Click the Next Button go to Maintenance Page
          break;
        }
      }
      ///AuDev10 is 维护页面
      Thread.Sleep(5000);
      AuDev10 = null;
      while (AuDev10 == null)
      {
        AuDev10 = Desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Microsoft Visual Studio 2010 Ultimate Setup - Maintenance Page"));
      }
      ControlList = AuDev10.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
      ///[0] is "Add or Remove"
      ///[1] is "Repair"
      ///[2] is "Remove"
      ///[3] is "< Previous"
      ///[4] is "Next >"
      ///[5] is "Cancel
      NextTar = ControlList[1];
      InvokePattern Inext = (InvokePattern)NextTar.GetCurrentPattern(InvokePattern.Pattern);
      Inext.Invoke();

 

VS的维护页面有三个linkbutton,分别是"add or remove","repair","uninstall" 我用
InvokePattern来对这3个linkbutton 进行点击操作,但是Inext.Invoke();执行的结果却仅仅只是让
“repair"这linkbutton获取焦点,并没有执行click事件进行修复.

寻求高手帮助,如何才能成功执行那3个link的click事件 

Object.prototype的主页 Object.prototype | 初学一级 | 园豆:155
提问于:2010-05-05 09:28
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册