javascript - 如何使用 Javascript onclick 自动化 Excel 从 Internet Explorer 下载 PDF
问题描述
我有一个自动化 Internet Explorer 的代码,将 IE 可见性设置为 false,以便代码在后台运行。我的代码单击一个元素 ID,该 ID 打开一个单独的 IE 窗口,该窗口可见并包含 PDF 报告。不幸的是,我无法打开新的 IE 窗口,但仍然不可见并将 PDF 的副本下载到计算机桌面。
我尝试使用报告直接导航到新打开页面的链接,但是链接可能会有所不同。
我在网站上单击元素“btnContinue”以打开报告:
<input name="btnContinue" class="btn btn-primary" id="btnContinue" onclick="javascript:pop('Splash.aspx?SplashID=3&../Reports/View.aspx&ReporttypeID=1&lang=EN&ruletypeid=5&ruleid=0'); return false;" type="submit" value="Continue">
这是我的代码:
Sub navigate()
Const url = "https://myURL"
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie 'Open IE
.navigate url
ieBusy ie
.Visible = False
If Item.ID = "btnNextPage" Then
Item.Click
Exit For
End If
Next
ieBusy ie
‘Below code clicks the element ID and opens a new IE with the report – Code needs to open a new IE but visibility remain false and download the newly opened report OR report triggered to be downloaded directly from element/javascript onclick.
For Each Item In ie.document.all
If Item.ID = "btnContinue" Then
Item.Click
Exit For
End If
Next
ieBusy ie
End With 'End IE actions
End Sub
Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.ReadyState < 4
DoEvents
Loop 'Loop
End Sub
我需要此代码来打开新页面,保持不可见,并将 PDF 下载到桌面或以某种方式触发报告从 onclick 下载(如果可能),而无需通过单击元素打开新页面。我试图导航/触发 javascript onclick 事件以查看是否可以直接下载报告,而无需单击元素以在新窗口中打开报告,但不幸的是没有任何成功。任何帮助将不胜感激。
解决方案
推荐阅读
- java - 出于安全原因升级 Java 运行时,无需使用较新的 Java 版本重新编译应用程序
- c# - 在 css 选择器中带有 Selenium 变量的 Visual Basic C#
- sql-server - 多实例的实体框架迁移策略
- java - 干燥控制器 - 返回实体或重定向的方法(在 Java、Spring 中)
- c# - 允许选择中的自由文本
- python - 高级冰雹 - 嵌套循环/组合
- python - 如何将模型从 H2O Web UI Flow 加载到 python?
- c - macOS 上的 C 程序无法打开其输入文件
- mysql - 连接到远程 MySQL 的 Excel VBA 中的错误处理
- php - 有没有办法只显示总和的一行,目前它显示两行作为输出