回答編集履歴
1
C#版の追加
test
CHANGED
@@ -189,3 +189,173 @@
|
|
189
189
|
|
190
190
|
|
191
191
|
```
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
---
|
196
|
+
|
197
|
+
C#版を追加しました。
|
198
|
+
|
199
|
+
参照の追加からCOMを選んでUIAUtomationClientをチェックしてください。
|
200
|
+
|
201
|
+
![COM](ca721ca478bc6e9e53f1292434ede053.png)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
``` C#
|
208
|
+
|
209
|
+
using System;
|
210
|
+
|
211
|
+
using UIAutomationClient;
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
namespace ConsoleApp1
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
class Program
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
[STAThread]
|
224
|
+
|
225
|
+
static void Main(string[] args)
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
string CLSID_CUIAutomation = "ff48dba4-60ef-4201-aa87-54103eef594e";
|
230
|
+
|
231
|
+
Type type = Type.GetTypeFromCLSID(Guid.Parse(CLSID_CUIAutomation));
|
232
|
+
|
233
|
+
IUIAutomation automation = Activator.CreateInstance(type) as IUIAutomation;
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
IUIAutomationElement root = automation.GetRootElement();
|
238
|
+
|
239
|
+
IUIAutomationTreeWalker walker = automation.RawViewWalker;
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
IUIAutomationElement edge = null;
|
244
|
+
|
245
|
+
edge = walker.GetFirstChildElement(root);
|
246
|
+
|
247
|
+
while (edge != null)
|
248
|
+
|
249
|
+
{
|
250
|
+
|
251
|
+
string name = edge.CurrentName;
|
252
|
+
|
253
|
+
if(!string.IsNullOrEmpty(name) && name .EndsWith(" - Microsoft Edge"))
|
254
|
+
|
255
|
+
{
|
256
|
+
|
257
|
+
break;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
IUIAutomationElement next= walker.GetNextSiblingElement(edge);
|
262
|
+
|
263
|
+
edge = next;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
if (edge == null)
|
268
|
+
|
269
|
+
{
|
270
|
+
|
271
|
+
return;
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
//Edge配下のタイトルが取得できそうなエレメントを取得
|
278
|
+
|
279
|
+
IUIAutomationElement m_tabContentDCompVisualElement = null;
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
const int UIA_AutomationIdPropertyId = 30011;
|
284
|
+
|
285
|
+
var cond = automation.CreatePropertyCondition(UIA_AutomationIdPropertyId,
|
286
|
+
|
287
|
+
"m_tabContentDCompVisualElement");
|
288
|
+
|
289
|
+
m_tabContentDCompVisualElement = edge.FindFirst(TreeScope.TreeScope_Subtree, cond);
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
if (m_tabContentDCompVisualElement == null)
|
296
|
+
|
297
|
+
{
|
298
|
+
|
299
|
+
return;
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
//タイトル
|
306
|
+
|
307
|
+
string title = m_tabContentDCompVisualElement.CurrentName;
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
//Edge配下のURLが取得できそうなエレメントを取得
|
312
|
+
|
313
|
+
IUIAutomationElement ie_server;
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
const int UIA_ClassNamePropertyId = 30012;
|
318
|
+
|
319
|
+
var cond = automation.CreatePropertyCondition(UIA_ClassNamePropertyId, "Internet Explorer_Server");
|
320
|
+
|
321
|
+
ie_server = edge.FindFirst(TreeScope.TreeScope_Subtree, cond);
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
if (ie_server == null)
|
330
|
+
|
331
|
+
{
|
332
|
+
|
333
|
+
return;
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
//URL
|
340
|
+
|
341
|
+
string url = ie_server.CurrentName;
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
Console.WriteLine(title);
|
346
|
+
|
347
|
+
Console.WriteLine(url);
|
348
|
+
|
349
|
+
Console.ReadKey();
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
```
|