参照で
UIAutomationClient
UIAutomationTypes
追加しとくこと
Process[] procsEdge = Process.GetProcessesByName("msedge");
foreach (Process process in procsEdge)
{
// the chrome process must have a window
if (process.MainWindowHandle == IntPtr.Zero)
{
continue;
}
AutomationElementCollection roots = AutomationElement.RootElement.FindAll(TreeScope.Element | TreeScope.Children, new AndCondition(new PropertyCondition(AutomationElement.ProcessIdProperty, process.Id), new PropertyCondition(AutomationElement.ClassNameProperty, "Chrome_WidgetWin_1")));
foreach (AutomationElement rootElement in roots)
{
// NamePropertyは Visual Studioについてくる inspect.exe で探す
AutomationElement address = rootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "アドレスと検索バー"));
if (address == null) {
// 英語対応はしとく
address = rootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "address and search bar"));
if (address == null)
{
continue;
}
}
ValuePattern v = (ValuePattern)address.GetCurrentPattern(ValuePattern.Pattern);
if (v.Current.Value != null && v.Current.Value != "")
{
Console.WriteLine("URL:" + v.Current.Value);
}
}
}