在IE11中查找button(IUIAutomationElement)

我一直在试图使用下面的链接给出的代码,但我不能让它与IE 11的工作。

自动为IE9(vba)saveas dialouge

为了方便复制代码:

Option Explicit Dim ie As InternetExplorer Dim h As LongPtr Private Declare PtrSafe Function FindWindowEx Lib "user32" _ Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, _ ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, _ ByVal lpsz2 As String) As LongPtr Sub Download() Dim o As IUIAutomation Dim e As IUIAutomationElement Set o = New CUIAutomation h = ie.Hwnd h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString) If h = 0 Then Exit Sub Set e = o.ElementFromHandle(ByVal h) Dim iCnd As IUIAutomationCondition Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save") Dim Button As IUIAutomationElement Set Button = e.FindFirst(TreeScope_Subtree, iCnd) Dim InvokePattern As IUIAutomationInvokePattern Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId) InvokePattern.Invoke End Sub 

没有find该button,意味着执行后

 Set Button = e.FindFirst(TreeScope_Subtree, iCnd) 

button仍然是“没有”。 IE11在这方面与IE11有什么不同? 我应该改变“PropertyCondition”到别的东西还是我在这里做错了什么? 谢谢。

不知道这是否解决您的问题,但也许你正在使用不同于“EN-US”的安装语言的IE浏览器。 在这种情况下,你应该更换

 Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save") 

通过你可以逐字从button上取得的属性名称,例如“DE-DE”

 Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Speichern") 

这对我有帮助。 不过,我觉得它很恶心….