投稿者 魔界の仮面弁士  (社会人) 投稿日時 2023/1/3 10:36:50
検索条件指定でヒットしない理由は、 "WebView" と "Chrome_RenderWidgetHostHWND" の
IsControlElement が false である点にあるようです。

FindFirst は RawTree ではなく ControlTree を探索するため、
ターゲット要素が IsControlElement = true でないと拾えないのだとか。
https://stackoverflow.com/questions/14187110/uiautomation-wont-retrieve-children-of-an-element

過去には、IsControlElement が予期せず変化してしまう不具合もあったそうな…。
https://github.com/microsoft/microsoft-ui-xaml/issues/3259

> Viewから
> Set aryElm = elmOne.FindAll(TreeScope_Children, uiAuto.CreateTrueCondition)
> Set elmSecond = aryElm.GetElement(0)
> こうすると、
> elmSecondは=Visual Basic 中学校(Name)(a)の要素を取得します。

Inspect の [Options] メニューを [Raw View] から [Control View] に切り替えてみてください。

[Options] - [Control View] 時の見え方
┣{ClassName = "View", Name = "", ControlType = Pane(0xC371)}
┃┗{ClassName = "", Name = "Visual Basic 中学校", ControlType = Document(0xC36E)}

[Options] - [Raw View] 時の見え方
┣{ClassName = "View", Name = "", ControlType = Pane(0xC371)}
┃┣{ClassName = "WebView", Name = "", ControlType = Document(0xC36E)}
┃┗{ClassName = "Chrome_RenderWidgetHostHWND", Name = "Chrome Legacy Window", ControlType = Pane(0xC371)}
┃ ┗{ClassName = "", Name = "Visual Basic 中学校", ControlType = Document(0xC36E)}
┃  ┣{ClassName = "MainTitle", Name = "Visual Basic 中学校", ControlType = Text(0xC364)}
┃  :


Dim uiAuto As CUIAutomation8: Set uiAuto = New CUIAutomation8
Dim ui(0 To 15) As IUIAutomationElement9

' {ClassName = "View", Name = "", ControlType = UIA_PaneControlTypeId (0xC371)} 
Set ui(0) = GetTargetView(uiAuto)  ' ← 目標の ClassName = "View" を取得する関数  

' Nothing 
Set ui(1) = ui(0).FindFirst(TreeScope_Children, uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "WebView"))
Set ui(2) = ui(0).FindFirst(TreeScope_Children, uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "Chrome_RenderWidgetHostHWND"))

' {ClassName = "WebView", Name = "", ControlType = UIA_DocumentControlTypeId(0xC36E)} 
Set ui(3) = uiAuto.RawViewWalker.GetFirstChildElement(ui(0))

' {ClassName = "Chrome_RenderWidgetHostHWND", Name = "Chrome Legacy Window", ControlType = UIA_PaneControlTypeId (0xC371)} 
Set ui(4) = uiAuto.RawViewWalker.GetNextSiblingElement(ui(3))

' {ClassName = "", Name = "Visual Basic 中学校", ControlType = UIA_DocumentControlTypeId(0xC36E)} 
Set ui(5) = uiAuto.ControlViewWalker.GetFirstChildElement(ui(0))
Set ui(6) = uiAuto.ContentViewWalker.GetFirstChildElement(ui(0))
Set ui(7) = ui(0).FindFirst(TreeScope_Children, uiAuto.RawViewCondition)
Set ui(8) = ui(0).FindFirst(TreeScope_Children, uiAuto.ControlViewCondition)
Set ui(9) = ui(0).FindFirst(TreeScope_Children, uiAuto.ContentViewCondition)

' {ClassName = "MainTitle", Name = "Visual Basic 中学校", ControlType = UIA_TextControlTypeId(0xC364)} 
Set ui(10) = ui(4).FindFirst(TreeScope_Children, uiAuto.CreatePropertyConditionEx(UIA_NamePropertyId, "中学", PropertyConditionFlags_MatchSubstring))
Set ui(11) = ui(4).FindFirst(TreeScope_Children, uiAuto.CreateTrueCondition())
Set ui(12) = ui(4).FindFirst(TreeScope_Children, uiAuto.RawViewCondition)
Set ui(13) = ui(4).FindFirst(TreeScope_Children, uiAuto.ControlViewCondition)
Set ui(14) = ui(4).FindFirst(TreeScope_Children, uiAuto.ContentViewCondition)
Set ui(15) = uiAuto.RawViewWalker.GetFirstChildElement(ui(5))


 <Inspect の Raw View で確認できる階層> 先頭の■は IsControlElement の 🟩true/🟥false を示す
⊟🟩[Pane]"View" ←………………………………………………… ui(0)
┣⊞🟥[Document]"WebView" ←……………………………………… ui(3)
┗⊞🟥[Pane]"Chrome_RenderWidgetHostHWND" ←………………… ui(4)
  ┗⊟🟩[Document]"" {Name = "Visual Basic 中学校"} ←… ui(5~9)
    ┣⊞🟩[Text]"MainTitle" ←……………………………… ui(10~15)
    :