我一直在尝试使用下面链接中给出的代码,但我无法使用IE 11。
Automate saveas dialouge for IE9 (vba)
为方便起见,复制代码:
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
找不到按钮,表示执行
后Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
按钮仍然“没有”。 IE11在这方面是否与IE9有什么不同?我应该将“PropertyCondition”更改为其他内容还是我在这里做错了什么?谢谢。
答案 0 :(得分:1)
不确定这是否解决了您的问题,但您可能正在使用不同于" EN-US"的安装语言的IE。在这种情况下,您应该替换
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
您可以从按钮逐字记录的属性名称,例如为" DE-DE"
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Speichern")
这对我有帮助。但是我发现它很恶心......