none
使用UI Automation编写代码自动安装,修复,卸载VS2010,但是无法成功执行"repair"这个linkbutton RRS feed

  • 问题

  •  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();
    上面代码是自动开始修复vs2010
    NextTar = ControlList[1];就是vs2010维护页面上的"Repair/Reinstall"这个linkbutton
    Inext.Invoke()就是点击那个linkbutton, 预期是执行Invoke后VS就开始修复了,但是当执行了那句代码后并没有鼠标点击linkbutton开始安装
    而仅仅是"Repair/Reinstall"这个linkbutton获取了焦点而已,并没切换到安装页面开始修复.

    add or remove , uninstall的效果也都是获取了焦点而已.

    求高手帮忙


    Dragon
    • 已更改类型 陈剑 2010年5月6日 3:17
    • 已更改类型 陈剑 2010年5月10日 9:41
    2010年5月4日 14:32