我试图将UI自动化与ChromiumWebBrowser结合使用,因此我通过将force-renderer-accessibility
命令行选项传递给设置来使其能够正常工作。它在inspect.exe工具上可用,但是我仍然无法通过代码找到它。谁能给我一个代码示例?
这是我初始化ChromiumWebBrowser
的方式:
void InitializeChromiumWebBrowser()
{
var settings = new CefSettings()
{
CefCommandLineArgs = {
new KeyValuePair<string, string>("force-renderer-accessibility", "true")
},
MultiThreadedMessageLoop = false
};
Cef.Initialize(settings);
m_chromeBrowser = new ChromiumWebBrowser("http://127.0.0.1/calc.html");
m_chromeBrowser.Name = "chromiumWebBrowser";
var t = new Timer { Interval = 5 };
t.Start();
t.Tick += (s, e) => BeginInvoke((Action)(() => Cef.DoMessageLoopWork()));
m_chromeBrowser.LoadingStateChanged += M_chromeBrowser_LoadingStateChanged;
browser_tabPage.Controls.Add(m_chromeBrowser);
}
我正在尝试使用UI自动化来操作它们,但是甚至找不到顶部窗口:
using (var proc = Process.GetCurrentProcess())
{
var root = AutomationElement.FromHandle(proc.MainWindowHandle);
var browser = root.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ClassNameProperty, "CefBrowserWindow")); // Always null
}
但是browser
始终是null
。我想念什么?