提问人:FELIX A 提问时间:1/23/2020 最后编辑:FELIX A 更新时间:1/29/2020 访问量:222
Powershell“InternetExplorer.Application”单击下拉列表
Powershell "InternetExplorer.Application" click on dropdown
问:
我正在尝试使用 Powershell 单击“CSV(逗号分隔)”,以便能够保存此报告。
这是下拉列表背后的代码。
<div class="MenuBarBkGnd" id="ReportViewerControl_ctl09_ctl04_ctl00_Menu" style="display: block; visibility: visible; position: absolute; z-index: 1;">
<div class="DisabledButton">
<a title="XML file with report data" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('XML');" href="javascript:void(0)" alt="XML file with report data">XML file with report data</a>
</div><div class="DisabledButton">
<a title="CSV (comma delimited)" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('CSV');" href="javascript:void(0)" alt="CSV (comma delimited)">CSV (comma delimited)</a>
</div><div class="DisabledButton">
<a title="PDF" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('PDF');" href="javascript:void(0)" alt="PDF">PDF</a>
</div><div class="DisabledButton">
<a title="MHTML (web archive)" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('MHTML');" href="javascript:void(0)" alt="MHTML (web archive)">MHTML (web archive)</a>
</div><div class="DisabledButton">
<a title="Excel" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('EXCELOPENXML');" href="javascript:void(0)" alt="Excel">Excel</a>
</div><div class="DisabledButton">
<a title="TIFF file" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('IMAGE');" href="javascript:void(0)" alt="TIFF file">TIFF file</a>
</div><div class="DisabledButton">
<a title="Word" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('WORDOPENXML');" href="javascript:void(0)" alt="Word">Word</a>
</div><div class="HoverButton">
<a title="TXT (Pipe delimited)" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('PIPE');" href="javascript:void(0)" alt="TXT (Pipe delimited)">TXT (Pipe delimited)</a>
</div>
<div style="left: 0px; top: 0px; width: 26px; height: 368px; position: absolute; z-index: -1; opacity: 0.05; background-color: black;"></div></div>
下面的代码显示下拉列表。
$DownloadButton = $ie.Document.getElementById('ReportViewerControl_ctl09_ctl04_ctl00_ButtonImgDown')
$DownloadButton.click()
答:
0赞
Deepak-MSFT
1/27/2020
#1
我试图用你的代码进行测试。我在单击CSV(逗号分隔)选项时放置了一条警报消息。因此,当代码单击该特定选项时,它将显示一条警报消息。这表示代码单击正确的元素。
这是修改后的 HTML:
<!doctype html>
<html>
<head>
<script>
function abc()
{
alert("Clicked...");
}
</script>
</head>
<body>
<div class="MenuBarBkGnd" id="ReportViewerControl_ctl09_ctl04_ctl00_Menu" style="display: block; visibility: visible; position: absolute; z-index: 1;">
<div class="DisabledButton">
<a title="XML file with report data" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('XML');" href="javascript:void(0)" alt="XML file with report data">XML file with report data</a>
</div><div class="DisabledButton">
<a title="CSV (comma delimited)" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="abc()" href="javascript:void(0)" alt="CSV (comma delimited)">CSV (comma delimited)</a>
</div><div class="DisabledButton">
<a title="PDF" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('PDF');" href="javascript:void(0)" alt="PDF">PDF</a>
</div><div class="DisabledButton">
<a title="MHTML (web archive)" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('MHTML');" href="javascript:void(0)" alt="MHTML (web archive)">MHTML (web archive)</a>
</div><div class="DisabledButton">
<a title="Excel" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('EXCELOPENXML');" href="javascript:void(0)" alt="Excel">Excel</a>
</div><div class="DisabledButton">
<a title="TIFF file" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('IMAGE');" href="javascript:void(0)" alt="TIFF file">TIFF file</a>
</div><div class="DisabledButton">
<a title="Word" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('WORDOPENXML');" href="javascript:void(0)" alt="Word">Word</a>
</div><div class="HoverButton">
<a title="TXT (Pipe delimited)" class="ActiveLink" style="padding: 8px 8px 3px; font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ReportViewerControl').exportReport('PIPE');" href="javascript:void(0)" alt="TXT (Pipe delimited)">TXT (Pipe delimited)</a>
</div>
<div style="left: 0px; top: 0px; width: 26px; height: 368px; position: absolute; z-index: -1; opacity: 0.05; background-color: black;"></div></div>
</body>
</html>
VBA代码:
Sub demo()
Dim URL As String
Dim IE As Object
Dim i As String
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "D:\Backup20190913\tests\391.html"
IE.Navigate URL
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
i = IE.document.getelementsbytagname("a").Item(1).innerHTML
If i = "CSV (comma delimited)" Then
IE.document.getelementsbytagname("a").Item(1).Click
End If
Set IE = Nothing
End Sub
此VBA代码将找到链接,并尝试将其innerHTML与静态值匹配。如果它匹配,那么它将单击它。
输出:
此外,您可以尝试根据自己的要求修改代码。如果您有任何问题,可以告诉我们。
评论
0赞
FELIX A
1/27/2020
谢谢!这非常有帮助。我觉得我离得很近。这就是我现在正在尝试的:但它不起作用......返回$DownloadCSV = $ie.Document.getElementsByTagName('a') | ?{$_.innerHTML -eq "CSV (comma delimited)"} $DownloadCSV.innerText $DownloadCSV.click()
CSV (comma delimited) System.__ComObject
0赞
FELIX A
1/27/2020
实际上,它奏效了!由于昨晚不活动,该网站已将我注销!你太棒了!好吧,你们都很棒!非常感谢!
评论