我正在尝试UIAutomate一个FlashSite。
但代码"冻结"即控制永远不会返回给我, findall 行没有错误。
我可能做错了什么?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Windows.Automation;
namespace WebFinger
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process[] firefoxes = Process.GetProcessesByName("firefox");
Process firefox = firefoxes[0];
AutomationElement rootElement = AutomationElement.FromHandle(firefox.MainWindowHandle);
if (rootElement == null)
{
Console.WriteLine("Hmm");
}
foreach (AutomationElement element in rootElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)))
{
Console.WriteLine("Here: " + element.Current.ToString());
}
}
}
}
答案 0 :(得分:2)
搜索范围与方法所在的元素有关 叫做。元素按照它们的顺序返回 在树上遇到。
在桌面上搜索顶级窗口时,请务必在范围内指定子级,而不是后代。通过搜索 桌面的整个子树可以遍历数千个项目 并导致堆栈溢出。
如果您的客户端应用程序可能会尝试 要在自己的用户界面中查找元素,您必须创建所有UI 自动化调用单独的线程。