PDA

View Full Version : Impossible to trigger a value input in a menu with VBA (javascript)



laure908
04-10-2018, 05:48 PM
Hi all,

I am a newbie with VBA but with help from different websites, I managed to create a macro that will connect to a certain website and fill a menu with a value "Closed" then click on OK. The problem is the value appears in the menu but it is as if it was not recognized as such. When OK is clicked it says that no value has been entered.

Here is the HTML code :


<div class="modal ui-dialog-content ui-widget-content" id="pausingModal" scrolltop="0" scrollleft="0" style="width: auto; min-height: 0px; height: auto;"><label>Please specify the reason</label><div class="row"><div class="select2-container select2 reason select2-container-active select2-dropdown-open" id="s2id_autogen2" style="width: 100%"><a href="javascript:void(0)" class="select2-choice select2-default" tabindex="-1"> <span class="select2-chosen" id="select2-chosen-3">Select a reason</span><abbr class="select2-search-choice-close"></abbr> <span class="select2-arrow" role="presentation"><b role="presentation"></b></span></a><label for="s2id_autogen3" class="select2-offscreen"></label><input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-3" id="s2id_autogen3" disabled=""></div><select class="select2 reason select2-offscreen" style="width: 100%" tabindex="-1" title=""><option></option><optgroup label="Related"><option data-pause-type="hard_pause" data-show-text-area="false" value="1">Closed</option>

Here is the VBA code :


'Select the reason For Each obj In objIE.Document.getElementsByTagName("span")
If obj.id = "select2-chosen-3" Then
obj.Focus
obj.innerText = "Closed"
Exit For
End If
Next

' Wait
Do While objIE.Busy = True
DoEvents
Loop
Do While objIE.readyState <> 4
DoEvents
Loop
Sleep 待ち時間


Up until here the value appears in the box. But it is like it doesn't get really selected. I tried the following code to add to it to trigger the value :


'Trigger the value
For Each obj In objIE.Document.getElementsByTagName("a")
If obj.className = "select2-choice select2-default" Then
obj.Click
Exit For
End If
Next

' Wait
Do While objIE.Busy = True
DoEvents
Loop
Do While objIE.readyState <> 4
DoEvents
Loop
Sleep 待ち時間

The last part is also working well as the button is clicked but a message says No option selected.


'Click on OK
For Each obj In objIE.Document.getElementsByTagName("a")
If obj.id = "submit-pause" Then
obj.Click
Exit For
End If
Next

Could somebody help me figure out what I am missing here ?