I woud like to buy on gdax automatically. But my inputs in the Amount window doesn´t get recognized. I can see that on the little field, that says: Total (LTC) ≈ 0.00000000
My code:
Sub test()
Dim ObjIE As New InternetExplorer
Dim Ohtml As HTMLDocument
Dim HTMLtags As IHTMLElementCollection
Dim HTMLtag As IHTMLElement
Dim HTMLobjekt As IHTMLElement
Dim item_limit As Object
Dim y As Integer
With ObjIE
.Visible = True
.navigate "https://www.gdax.com/trade/LTC-EUR"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set Ohtml = .document
End With
'Amount
Do
Set HTMLtags = Ohtml.getElementsByClassName("OrderForm_input-box_XkGmi")
DoEvents
Loop While HTMLtags.Length = 0
For Each HTMLtag In HTMLtags
If HTMLtag.Children(1).innerText = "EUR" Then
Set HTMLobjekt = HTMLtag.Children(0)
HTMLobjekt.Value = 100 ' this is the part that i excanged
End If
Next HTMLtag
'get the Total(LTC) to cross check
Do
Set HTMLtags = Ohtml.getElementsByClassName("OrderForm_total_6EL8d")
DoEvents
Loop While HTMLtags.Length = 0
For Each HTMLtag In HTMLtags
Debug.Print HTMLtag.innerText & "Total(LTC)"
Next HTMLtag
End Sub
This is what the website says when the code is done:
and this is how it should look like, and looks when I type the number in manually:
I also exchange the marked part with things like:
HTMLobjekt.innerText = 100
or
HTMLobjekt.innerText = "100"
or
HTMLobjekt.Value = "100"
but nothing worked.
Not a complete answer, just a direction. Open the webpage https://www.gdax.com/trade/LTC-EUR in a browser (e. g. Chrome). Click to open context menu on the target element (step 1 on the below screenshot), click Inspect (2), from opened developer tools on the right you can see target element (3), and that there is a bunch of event listeners attached to target object (4). One of the handlers is
input
on thedocument
node level. Actually the amount is updated by this event handler, when event is bubbled from<input>
node. You can easily check that by deleting all other event handlers (click on their Remove buttons). But if you delete particularly thisinput
handler (5) then there will be no update (until you reload the webpage).So, to mimic user activity you need to create such
input
event object and dispatch it to the target<input>
node. Note<input>
node andinput
control event is completely different things just having the same name.Tracing event handler execution in IE can be done in debugger. Open IE developer tools (press F12), go to Debugger tab (step 1 on the below screenshot), Breakpoints tab (2), click Add event breakpoint (3), choose input event (4). Now any input event will pause code execution and open debugger window (5).
If you try to type in the amount textbox on the webpage, debugger will show event handler function code:
You may resume execution (F5), or make step into / over / out. To see event object passed to the function, type
arguments
in console, there is output for standard event handler call after typing manually:I tested the below test code to trigger that event from VBA:
As a result, absolutely the same actions take place as in case of typing the amount manually. It works without any errors. But Total (LTC) isn't updated. Debugger pauses execution as well, and the output for event object is as follows:
The only difference is that
isTrusted
property isTrue
for standard call, andFalse
for call via VBA. I guess that is why updating is skipped somewhere in the handler code. I tried to trace the entire code execution till event handler completion, but seems that is huge reverse engineering work, which I can't devote time for at the moment.Currently I'm stucked in my investigations at that point.
You need to make sure the page is fully loaded before you take any initiative. I checked for the availability of one such class generated dynamically
OrderBookPanel_text_33dbp
. Then I did the rest what you tried to do. Lastly, you need toFocus
the target before putting that amount in the placeholder. Applying all of the above, your script should more like below:Output at this moment:
Sorry could not get to work but have nudged along the problem.
I managed to figure out the correct syntax for creating and raising an event in higher versions of Internet Explorer (thanks to this SO answer ) . I managed to raise an input event for the input box, that followed on from omegastripes excellent lead.
So it works for a local file which I give below that has the same essential structure of the real page.
But when I run the code on the real page it simply does not work and I do not know why.
Where possible I'm feeding javascript into IE for it to execute to miminise issues with the VBA/COM/MSHTML interoperability bridge. I do this by calling
window.execScript
passing the javascript as a string.I hope someone can pick up this ball and run it over the goal line. For me, I have reached the end.
Here is the local html file
Here is the VBA