Я пытаюсь автоматизировать некоторые задачи в IE с помощью информации из файла Excel. Мои знания в VBA позволяют мне дойти до точки, где я отвечаю на вопрос на веб-сайте с «да», и это должно открыть другой вопрос с большим количеством вариантов для выбора.
Как я уже сказал, до первого да, но другой вопрос не появляется.
Вот часть кода JavaScript с веб-сайта и часть кода HTML:
var elemData = jQuery.data( elem );
// If no elemData is found then we must be trying to bind to one of the
// banned noData elements
if ( !elemData ) {
return;
}
var events = elemData.events = elemData.events || {},
eventHandle = elemData.handle, eventHandle;
if ( !eventHandle ) {
elemData.handle = eventHandle = function() {
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
jQuery.event.handle.apply( eventHandle.elem, arguments ) :
undefined;
};
<p>
<span class="i_lbReq">First question</span> //this line has the 'change: eventHandle' event/function associated to it
<br></br>
<select name="meetingQuestionAnswer(220674)" class="auto-save">
<option value=""> --- --- </option>
<option value="Yes" selected="">Yes</option>
<option value="No">No</option>
<option value="Pending">Pending</option>
</select>
</p>
<div class="recursive-question" id="meetingDependentQuestion(220674)"> //this line has the 'change: eventHandle' event/function associated to it
<div id="meetingQuestionAnswerDiv(221010)">
<input name="meetingQuestionValidatorRule(221010)" type="hidden" value="">
<input name="meetingQuestionReadOnly(221010)" type="hidden" value="">
<p>
<span class="i_lb">Dependent question 1</span>
<br></br>
<select name="meetingQuestionAnswer(221010)" class="auto-save">
<option value="" selected=""> --- --- </option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</p>
<div class="recursive-question" id="meetingDependentQuestion(221010)">
<div id="meetingQuestionAnswerDiv(221011)">
<input name="meetingQuestionValidatorRule(221011)" type="hidden" value="">
<input name="meetingQuestionReadOnly(221011)" type="hidden" value="">
<p>
<span class="i_lb">Dependent question 2</span>
<br></br>
<select name="meetingQuestionAnswer(221011)" class="auto-save">
<option value="" selected=""> --- --- </option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</p>
<div class="recursive-question" id="meetingDependentQuestion(221011)">
</div>
</div>
</div>
</div>
</div>
Я пытался с VBA использовать метод .FireEvent "onchange" для первого элемента вопроса, но он не работал
Dim ieApp As SHDocVw.InternetExplorer
Set ieApp = IEWindowFromTitle("Profile Form Detail View")
If Not ieApp Is Nothing Then
Set ieDoc = ieApp.document
End If
For Each cell In GMF.Sheets("BUDGET").Range("B4:B" & Cells(Rows.count, 2).End(xlUp).Row)
If cell.Value = "MRR" Then
ieDoc.getElementsByName("meetingQuestionAnswer(220674)")(0).Value = "Yes" 'this works fine
ieDoc.getElementsByName("meetingQuestionAnswer(220674)")(0).FireEvent "onchange"
ieDoc.getElementsByName("meetingQuestionAnswerDiv(221010)")(0).Value = "Yes" 'this one never appears after saying yes in the previous question
End If
Next cell