VBA/Незначительный HTML/Javascript: нажмите на хитрый скрытый флажок в отчете

117
7

Я ежедневно получаю отчет за работу, и я использую excel для создания командной кнопки для открытия IE, перехода к странице отчета, заполнения данных даты и времени, а затем остановки, поэтому я могу щелкнуть эти два флажка, которые мне нужно отметить. Мне бы очень хотелось, чтобы он мог проверить два флажка автоматически. Здесь HTML:

<table width="100%" class="msrs-contentFrame" cellpadding="0" cellspacing="0" height="100%">
<tbody><tr>
<td valign="top" height="100%"><span><table width="100%" class="msrs-normal" cellpadding="0" cellspacing="0" height="100%">
<tbody><tr>
<td valign="top" height="100%"><div id="NavigationCorrector" style="display:none;">
<input type="hidden" name="NavigationCorrector$ScrollPosition" id="NavigationCorrector_ScrollPosition"><input type="hidden" name="NavigationCorrector$ViewState" id="NavigationCorrector_ViewState"><input type="hidden" name="NavigationCorrector$PageState" id="NavigationCorrector_PageState"><div id="NavigationCorrector_ctl00">
<input type="hidden" name="NavigationCorrector$NewViewState" id="NavigationCorrector_NewViewState">
</div>
</div><noscript>
&nbsp;Your browser does not support scripts or has been configured not to allow scripts.
</noscript><span id="ctl31_ReportViewer"><div id="ctl31" onclick="if ($get('ctl31_ctl04') != null && $get('ctl31_ctl04').control != null) $get('ctl31_ctl04').control.HideActiveDropDown();" onactivate="if ($get('ctl31_ctl04') != null && $get('ctl31_ctl04').control != null) $get('ctl31_ctl04').control.HideActiveDropDown();" style="height: 100%; width: 100%;">
<div id="ctl31_HttpHandlerMissingErrorMessage" style="border-color:Red;border-width:2px;border-style:Solid;padding:10px;display:none;overflow:auto;font-size:.85em;">
<h2>
Report Viewer Configuration Error
</h2><p>The Report Viewer Web Control HTTP Handler has not been registered in the application web.config file. Add <add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, ReportingServicesWebUserInterface, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> to the system.web/httpHandlers section of the web.config file, or add <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, ReportingServicesWebUserInterface, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> to the system.webServer/handlers section for Internet Information Services 7 or later.</p>
</div><span id="ctl31_ctl03"><input type="hidden" name="ctl31$ctl03$ctl00" id="ctl31_ctl03_ctl00"><input type="hidden" name="ctl31$ctl03$ctl01" id="ctl31_ctl03_ctl01"></span><input type="text" name="ctl31$ctl10" id="ctl31_ctl10"><input type="hidden" name="ctl31$ctl11" id="ctl31_ctl11" value="quirks"><div id="ctl31_AsyncWait" style="background-color: white; opacity: 0.7; position: absolute; display: none; z-index: 1000;">

</div><div id="ctl31_AsyncWait_Wait" class="WaitControlBackground" style="display: none; position: absolute; z-index: 1001;">
<table height="100%">
<tbody><tr>
<td width="32px" height="32px"><img src="/ReportManager/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.50.4339.0&Name=Microsoft.Reporting.WebForms.Icons.SpinningWheel.gif" style="height:32px;width:32px;border-width:0px;"></td><td class="WaitInfoCell"><span class="WaitText">Loading...</span><div class="CancelLinkDiv">
<a class="CancelLinkText" href="javascript:$get('ctl31_AsyncWait').control._cancelCurrentPostback();">Cancel</a>
</div></td>
</tr>
</tbody></table>
</div><input type="hidden" name="ctl31$AsyncWait$HiddenCancelField" id="ctl31_AsyncWait_HiddenCancelField" value="False"><table cellpadding="0" cellspacing="0" id="ctl31_fixedTable" style="table-layout:fixed;width:100%;height:100%;">
<tbody><tr class="MenuBarBkGnd">
<td style="display:none;width:25%;"></td><td style="display:none;width:6px;"></td><td style="width:100%;"></td>
</tr><tr id="ParametersRowctl31">
<td colspan="3"><div id="ctl31_ctl04" style="width:100%;overflow-x:auto;overflow-y:hidden;">
<div onclick="if ($get('ctl31_ctl04') != null && $get('ctl31_ctl04').control != null) $get('ctl31_ctl04').control.HideActiveDropDown();" onactivate="if ($get('ctl31_ctl04') != null && $get('ctl31_ctl04').control != null) $get('ctl31_ctl04').control.HideActiveDropDown();">
<table cellpadding="0" cellspacing="0" width="100%" id="ParameterTable_ctl31_ctl04" name="ParameterTable_ctl31_ctl04" class="ParametersFrame ParamsGrid MenuBarBkGnd">
<tbody><tr>
<td width="100%" height="100%"><table id="ParametersGridctl31_ctl04">
<tbody><tr isparameterrow="true">
<td class="ParamLabelCell"><span>Show Start Date From:</span></td><td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl31_ctl04_ctl03">
<input name="ctl31$ctl04$ctl03$txtValue" type="text" size="30" id="ctl31_ctl04_ctl03_txtValue" class="null">
</div></td><td class="InterParamPadding"></td><td class="ParamLabelCell"><span>Show End Date To:</span></td><td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl31_ctl04_ctl05">
<input name="ctl31$ctl04$ctl05$txtValue" type="text" size="30" id="ctl31_ctl04_ctl05_txtValue" class="null">
</div></td>
</tr><tr isparameterrow="true">
<td class="ParamLabelCell"><span>Show Start Hour From:</span></td><td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl31_ctl04_ctl07">
<select name="ctl31$ctl04$ctl07$ddValue" id="ctl31_ctl04_ctl07_ddValue" style="width: 117px;">

<option value="1">00</option>
<option value="2">01</option>
<option value="3">02</option>
<option value="4">03</option>
<option value="5">04</option>
<option value="6">05</option>
<option value="7">06</option>
<option value="8">07</option>
<option selected="selected" value="9">08</option>
<option value="10">09</option>
<option value="11">10</option>
<option value="12">11</option>
<option value="13">12</option>
<option value="14">13</option>
<option value="15">14</option>
<option value="16">15</option>
<option value="17">16</option>
<option value="18">17</option>
<option value="19">18</option>
<option value="20">19</option>
<option value="21">20</option>
<option value="22">21</option>
<option value="23">22</option>
<option value="24">23</option>

</select>
</div></td><td class="InterParamPadding"></td><td class="ParamLabelCell"><span>Show Start Hour To:</span></td><td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl31_ctl04_ctl09">
<select name="ctl31$ctl04$ctl09$ddValue" id="ctl31_ctl04_ctl09_ddValue" style="width: 117px;">

<option value="1">00</option>
<option value="2">01</option>
<option value="3">02</option>
<option value="4">03</option>
<option value="5">04</option>
<option value="6">05</option>
<option value="7">06</option>
<option value="8">07</option>
<option value="9">08</option>
<option value="10">09</option>
<option value="11">10</option>
<option value="12">11</option>
<option value="13">12</option>
<option value="14">13</option>
<option value="15">14</option>
<option value="16">15</option>
<option value="17">16</option>
<option value="18">17</option>
<option value="19">18</option>
<option value="20">19</option>
<option value="21">20</option>
<option value="22">21</option>
<option value="23">22</option>
<option selected="selected" value="24">23</option>

</select>
</div></td>
</tr><tr isparameterrow="true">
<td class="ParamLabelCell"><span>Media Type:</span></td><td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl31_ctl04_ctl11">
<div onactivate="event.cancelBubble=true;" style="white-space:nowrap;">
<input name="ctl31$ctl04$ctl11$txtValue" type="text" size="28" readonly="readonly" id="ctl31_ctl04_ctl11_txtValue" class="null"><input src="/ReportManager/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.50.4339.0&Name=Microsoft.Reporting.WebForms.Icons.MultiValueSelect.gif" name="ctl31$ctl04$ctl11$ddDropDownButton" type="image" id="ctl31_ctl04_ctl11_ddDropDownButton" alt="Select a value" title="Select a value" style="vertical-align:top;cursor:pointer;">
</div>
</div></td>
</tr>
</tbody></table></td><td width="6px"></td><td class="SubmitButtonCell"><table>
<tbody><tr>
<td><input type="submit" name="ctl31$ctl04$ctl00" value="View Report" id="ctl31_ctl04_ctl00"></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table>
</div>
</div><iframe id="ctl31_ctl04_ctl11_ctl01" onclick="event.cancelBubble=true;" onactivate="event.cancelBubble=true;" style="display: none; position: absolute; z-index: 10; left: 144px; top: 110px; width: 187px; height: 97px;" src="javascript:'';" frameborder="0" title="Media Type: place holder" longdesc="Media Type: place holder" name="ctl31_ctl04_ctl11_ctl01"></iframe><div id="ctl31_ctl04_ctl11_divDropDown" onclick="event.cancelBubble=true;" onactivate="event.cancelBubble=true;" style="border-color: darkgray; border-width: 1px; border-style: solid; overflow: auto; background-color: window; display: none; position: absolute; z-index: 11; left: 144px; top: 110px; width: 187px;">
<input type="hidden" name="ctl31$ctl04$ctl11$divDropDown$HiddenIndices" id="ctl31_ctl04_ctl11_divDropDown_HiddenIndices" value="">
</div></td>
</tr><tr style="height:6px;font-size:2pt;">
<td colspan="3" class="SplitterNormal" style="padding: 0px; margin: 0px; text-align: center; cursor: default;"><div id="ctl31_ToggleParam">
<input type="image" name="ctl31$ToggleParam$img" id="ctl31_ToggleParam_img" title="Show / Hide Parameters" src="/ReportManager/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.50.4339.0&Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapse.png" alt="Show / Hide Parameters" align="middle" onclick="void(0);" style="border-width:0px;cursor:pointer;"><input type="hidden" name="ctl31$ToggleParam$store" id="ctl31_ToggleParam_store"><input type="hidden" name="ctl31$ToggleParam$collapse" id="ctl31_ToggleParam_collapse" value="false">
</div></td>
</tr><tr style="display:none;">

</tr><tr>
<td style="vertical-align:top;width:25%;height:100%;display:none;"><div style="width:100%;height:100%;">
<span id="ctl31_DocMap"><div id="ctl31_ctl08" style="display:none;">
<input type="hidden" name="ctl31$ctl08$ClientClickedId" id="ctl31_ctl08_ClientClickedId">
</div></span>
</div></td><td class="SplitterNormal" style="display:none;width:4px;padding:0px;margin:0px;height:100%;vertical-align:middle;"><div id="ctl31_ctl07">
<input type="image" name="ctl31$ctl07$img" id="ctl31_ctl07_img" title="Show / Hide Document Map" src="/ReportManager/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.50.4339.0&Name=Microsoft.Reporting.WebForms.Icons.SplitterVertCollapse.png" alt="Show / Hide Document Map" align="top" onclick="void(0);" style="border-width:0px;cursor:pointer;"><input type="hidden" name="ctl31$ctl07$store" id="ctl31_ctl07_store"><input type="hidden" name="ctl31$ctl07$collapse" id="ctl31_ctl07_collapse" value="false">
</div></td><td style="height:100%;vertical-align:top;"><div id="ctl31_ctl09" style="height:100%;width:100%;overflow:auto;position:relative;">
<div id="VisibleReportContentctl31_ctl09" style="height:100%;display:none;"></div><div id="ctl31_ctl09_ReportArea">
<div newcontenttype="Microsoft.Reporting.WebFormsClient.ReportAreaContent.None" fornonreportcontentarea="false" id="ctl31_ctl09_VisibilityState" style="visibility:none;">
<input type="hidden" name="ctl31$ctl09$VisibilityState$ctl00" value="None">
</div><input type="hidden" name="ctl31$ctl09$ScrollPosition" id="ctl31_ctl09_ScrollPosition"><span id="ctl31_ctl09_Reserved_AsyncLoadTarget"></span><div id="ctl31_ctl09_ReportControl" style="display:none;">
<span></span><input type="hidden" name="ctl31$ctl09$ReportControl$ctl02"><input type="hidden" name="ctl31$ctl09$ReportControl$ctl03"><input type="hidden" name="ctl31$ctl09$ReportControl$ctl04" id="ctl31_ctl09_ReportControl_ctl04" value="100">
</div><div id="ctl31_ctl09_NonReportContent" style="height: 100%; width: 100%; display: none;">

</div>
</div>
</div></td>
</tr>
</tbody></table>
</div></span></td>
</tr>
</tbody></table>
</span></td>
</tr>
</tbody></table>

Флажки, которые я хотел бы щелкнуть, следующие:

 <input id="ctl31_ctl04_ctl11_divDropDown_ctl03" type="checkbox" name="ctl31$ctl04$ctl11$divDropDown$ctl03" onclick="$get('ctl31_ctl04_ctl11').control.OnValidValueClick(this, 'ctl31_ctl04_ctl11_divDropDown_ctl00');">

а также

 <input id="ctl31_ctl04_ctl11_divDropDown_ctl04" type="checkbox" name="ctl31$ctl04$ctl11$divDropDown$ctl04" onclick="$get('ctl31_ctl04_ctl11').control.OnValidValueClick(this, 'ctl31_ctl04_ctl11_divDropDown_ctl00');">

Однако они скрыты внутри выпадающего меню

 <input src="/ReportManager/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.50.4339.0&Name=Microsoft.Reporting.WebForms.Icons.MultiValueSelect.gif" name="ctl31$ctl04$ctl11$ddDropDownButton" type="image" id="ctl31_ctl04_ctl11_ddDropDownButton" alt="Select a value" title="Select a value" style="vertical-align:top;cursor:pointer;">

Внутри стола

 <table id="ParametersGridctl31_ctl04">

... который находится внутри, по крайней мере, трех или четырех таблиц и разделов. Есть ли простой способ щелкнуть по нему/установить значение TRUE?

Здесь VBA я использую то, что не работает, вы можете видеть, что я пытаюсь использовать несколько разных методов:

    Dim oCheckBox1 As Object
Set oCheckBox1 = IE.document.getElementById("ctl31_ctl04_ctl11_divDropDown_ctl03")

Dim oCheckBox2 As Object
Set oCheckBox2 = IE.document.getElementById("ctl31_ctl04_ctl11_divDropDown_ctl04")

HWNDSrc = IE.HWND
'Set IE as Active Window
SetForegroundWindow HWNDSrc

oCheckBox1.Click , True
Call IE.document.parentWindow.execScript("$get('ctl31_ctl04_ctl11').control.OnValidValueClick(this, 'ctl31_ctl04_ctl11_divDropDown_ctl00');", "JavaScript")
oCheckBox1.Checked = True
oCheckBox1.Value = True

oCheckBox2.Click , True
Call IE.document.parentWindow.execScript("$get('ctl31_ctl04_ctl11').control.OnValidValueClick(this, 'ctl31_ctl04_ctl11_divDropDown_ctl00');", "JavaScript")
oCheckBox2.Checked = True
oCheckBox2.Value = True
Dim oMediaType As Object
Set oMediaType = IE.document.getElementById("ctl31_ctl04_ctl11_txtValue")
oMediaType.Value = "[RESULT THAT COMES FROM CLICKING THE CHECKBOXES, REDACTED FOR PRIVACY]"

... затем я нажимаю кнопку "VIew Report"

Любая помощь?

спросил(а) 2021-01-19T20:34:15+03:00 6 месяцев назад
1
Решение
63

В соответствии с просьбой здесь приведен ответ. Элемент, который вы пытаетесь щелкнуть, имеет Event которое вызывается тем, что похоже на JavaScript.

Код страницы:

onclick="$get('ctl31_ctl04_ctl11').control.OnValidValueClick(this, 'ctl31_ctl04_ctl11_divDropDown_ctl00');

Вы должны вызвать это событие, чтобы выполнить код на странице, который активирует эту кнопку.

Упрощенный код:

 oCheckBox1.Click
oCheckBox1.FireEvent("OnClick")

ответил(а) 2021-01-19T20:34:15+03:00 6 месяцев назад
Ваш ответ
Введите минимум 50 символов
Чтобы , пожалуйста,
Выберите тему жалобы:

Другая проблема