使用python在internet explorer中单击“另存为”选项

使用python在internet explorer中单击“另存为”选项,python,internet-explorer,automation,Python,Internet Explorer,Automation,我正在尝试自动化下载一堆文件的过程。我使用的是Internet explorer版本11(这是其他浏览器无法兼容的唯一方法)。下载前的部分是自动完成的,但当点击下载链接时,IE会弹出一个窗口,显示打开、保存、另存为选项的天气 是否有任何python代码,我可以访问当前打开的IE并单击弹出窗口中的“另存为”按钮, 这是弹出窗口的快照 我必须单击旁边的向下箭头才能保存 这是我每次自动化都会导致错误的过程, 有人能帮忙吗 提前非常感谢据我所知,当您单击下载链接或按钮时,WebDriver无法访问浏

我正在尝试自动化下载一堆文件的过程。我使用的是Internet explorer版本11(这是其他浏览器无法兼容的唯一方法)。下载前的部分是自动完成的,但当点击下载链接时,IE会弹出一个窗口,显示打开、保存、另存为选项的天气


是否有任何python代码,我可以访问当前打开的IE并单击弹出窗口中的“另存为”按钮, 这是弹出窗口的快照 我必须单击旁边的向下箭头才能保存 这是我每次自动化都会导致错误的过程, 有人能帮忙吗



提前非常感谢

据我所知,当您单击下载链接或按钮时,WebDriver无法访问浏览器显示的IE下载对话框。但是,我们可以使用名为“”的单独程序绕过这些对话框。更多详细信息,您可以查看。

***编辑 找到更好/更容易的方法。另外,我将invoke方法包装在try语句中,这样您就可以在其他代码中使用它,并且在按钮可用之前,它不会尝试单击save/saveas

单击“保存”按钮:

import uiautomation as uia

SaveBtn = uia.SplitButtonControl(SearchDepth=4, Name = 'Save')

#wrap up the Invoke statement to try until the box shows up
while True:
    try:
        SaveBtn.GetInvokePattern().Invoke()
    except LookupError:
        time.sleep(0.5)
    else:
        break
要单击下拉列表以单击“另存为”并保存到位置,请执行以下操作:

import uiautomation as uia

SaveLocation = "C:\\Foobar\\FoobarDrive\\FobarMagic\\""
savestr = "Foobar.xlsx
#Click the Saveas Button on Internet Explorer Window

#clicking the down arrow next to save
SaveBtn = uia.SplitButtonControl(SearchDepth=5, Name = '6')

    #wrap up the Invoke statement to try until the box shows up
while True:
    try:
        SaveBtn.GetInvokePattern().Invoke()
    except LookupError:
        time.sleep(0.5)
    else:
        break

    #Find/map saveas button and click the saveas option
SaveasBtn = uia.MenuItemControl(SearchDepth=2, Name = 'Save as')
SaveasBtn.GetInvokePattern().Invoke()

    #Find Save as dialog and click on address bar
Savedlg = uia.WindowControl(SearchDepth=1, Name = 'Save As')

    #Name File
FileName = Savedlg.EditControl(SearchDepth=7,Name='File name:')
FileName.SendKeys(savestr)

    #Click on the Previous locations button to activate the Addressbar
PrevLocBtn = Savedlg.ButtonControl(SearchDepth=7,Name = 'Previous Locations')
PrevLocBtn.GetInvokePattern().Invoke()

    #Find the Address bar and clear it out
Addressbar = Savedlg.EditControl(SearchDepth=8, Name = 'Address')
Addressbar.SendKeys('{Back}')

    #Define Save Location and Send the string to the addressbar
Addressbar.SendKeys(SaveLocation)

    #Click go to directory button
Navigatebtn = Savedlg.ButtonControl(SearchDepth=6, Name= 'Go to ' + '"' + SaveLocation + '"')
while True:
    try:
        Navigatebtn.GetInvokePattern().Invoke()
    except LookupError:
        time.sleep(0.5)
    else:
        break

#Click Saveas Dlg Save Button
SaveBtn = Savedlg.ButtonControl(SearchDepth=2, Name="Save")
SaveBtn.GetInvokePattern().Invoke()

#Overwrite the old file if it exists
confirm = Savedlg.WindowControl(SearchDepth=2, Name = 'Confirm Save As')
confirmbtn = confirm.ButtonControl(SearchDepth=2, Name = 'Yes')

while True:
    try:
        confirmbtn.GetInvokePattern().Invoke()
    except:
        break
如何打开文件

#Click the Save Button on Internet Explorer Window

    #clicking the save button itself.
OpenBtn = uia.SplitButtonControl(SearchDepth=4, Name = 'Open')

    #wrap up the click statement to try until the box shows up
while True:
    try:
        OpenBtn.GetInvokePattern().Invoke()
    except LookupError:
        time.sleep(0.5)
    else:
        break

如何单击“保存”。我也有同样的问题。我无法单击“打开”。谢谢你的帮助。