[英]Download files automatically in Internet Explorer 11 with Python and Selenium
我正在尝试使用 Python 和 Selenium 同时通过多个 Internet Explorer 11 windows 下载一些 Excels 文件。 当“另存为”弹出窗口出现并且单击保存按钮的唯一方法是发送密钥(alt + s)时,问题就出现了。 但要做到这一点,焦点必须在浏览器 window 上,正如我之前所说,我需要同时启动多个 IE11 windows 并做同样的事情。
AutoIt、Robot 或仅事件发送密钥等工具无效,因为这些工具使用操作系统,我认为必须有像 javascript 或 Python 之类的解决方案来处理每个应该工作的 window 浏览器。
感谢您的帮助,谢谢!
据我所知,当您单击下载链接或按钮时,WebDriver 无法访问浏览器显示的 IE 下载对话框。 但是,我们可以使用名为“ wget ”的单独程序绕过这些对话框。
通过使用这个程序,我们首先可以得到超链接的href属性值,然后,执行命令提示符命令从链接中下载文件。
示例代码:
import time
import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreZoomSetting'] = True
driver = webdriver.Ie("D:\\Downloads\\webdriver\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe",capabilities= cap)
driver.get("<website url>")
time.sleep(3)
btn = driver.find_element_by_id("btnDowloadReport")
hrefurl = btn.get_attribute("href")
os.system('cmd /c D:\\temp\\wget.exe -P D:\\temp --no-check-certificate ' + hrefurl)
print("*******************")
Html 资源:
<a id="btnDowloadReport" href="https://github.com//sakinala/AutomationTesting/raw/master/samplefile.pdf" >Download</a>
【注意】:请记住将webdriver路径和网站url改成自己的。
有关使用 wget 的更多详细信息,您可以参考这篇文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.