网站无法识别我的输入 [如何从 VBA 手动触发 IE dom 事件] [英] Website does not recognize my inputs [how to fire IE dom event manually from VBA]

查看:17
本文介绍了网站无法识别我的输入 [如何从 VBA 手动触发 IE dom 事件]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动在 gdax 上购买.但是我在 Amount 窗口中的输入没有被识别.我可以在小字段上看到,上面写着:Total (LTC) ≈ 0.00000000

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

我的代码:

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

HTMLobjekt.innerText = "100"

HTMLobjekt.Value = "100"

但没有任何效果.

推荐答案

在采取任何措施之前,您需要确保页面已完全加载.我检查了动态生成的一个这样的类的可用性OrderBookPanel_text_33dbp.然后我做了你想做的剩下的事情.最后,您需要在将该数量放入占位符之前Focus 目标.应用以上所有内容,您的脚本应该更像以下内容:

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 to Focus the target before putting that amount in the placeholder. Applying all of the above, your script should more like below:

Sub Get_Value()
    Dim HTML As HTMLDocument, tags As Object
    Dim tag As Object, ival As Object

    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .navigate "https://www.gdax.com/trade/LTC-EUR"
        While .Busy = True Or .readyState < 4: DoEvents: Wend
        Set HTML = .document

        Do: Set tags = HTML.querySelector("[class^='OrderBookPanel_text_']"): DoEvents: Loop While tags Is Nothing
        Do: Set tag = HTML.querySelector("input[name='amount']"): DoEvents: Loop While tag Is Nothing
        tag.Focus
        tag.innerText = 100

        Set ival = HTML.querySelector("[class^='OrderForm_total_']")
        [A1] = ival.innerText
        .Quit
    End With
End Sub

此时输出:

0.79139546

这篇关于网站无法识别我的输入 [如何从 VBA 手动触发 IE dom 事件]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆