Powershell“ InternetExplorer.Appication”单击下拉列表

问题描述 投票:0回答:1

我正在尝试使用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()
html powershell internet-explorer dom automation
1个回答
0
投票

我试图用您的代码进行测试。我在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与静态值进行匹配。如果匹配,则将其单击。

输出:

enter image description here

此外,您可以尝试根据自己的要求修改代码。如果您有任何疑问,可以告诉我们。

© www.soinside.com 2019 - 2024. All rights reserved.