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

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

问题描述

我想自动购买gdax。但我在Amount窗口中的输入无法识别。我可以在小字段上看到:总计(LTC)≈0.00000000



我的代码:

 子测试()

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

使用ObjIE
.Visible = True
.navigatehttps://www.gdax.com/trade/LTC-EUR
Do Until .readyState = READYSTATE_COMPLETE:Loop
Set Ohtml = .document
End with

'金额
Do
设置HTMLtags = Ohtml.getElementsByClassName(OrderForm_input-box_XkGmi)
DoEvents
循环,而HTMLtags.Length = 0
每个HTML标签在HTML标签中
如果HTMLtag.Children(1).innerText =EUR那么
设置HTMLobjekt = HTMLtag.Children(0)
HTMLobjekt.Value = 100'这是我放弃的部分
结束如果
下一个HTMLtag

'获得总计(LTC) )交叉检查
Do
设置HTMLtags = Ohtml.getElementsByClassName(OrderForm_total_6EL8d)
DoEvents
循环,而HTMLtags.Length = 0
每个HTML标签在HTMLtags $中b $ b Debug.Print HTMLtag.innerText& 总计(LTC)
下一个HTMLtag

结束次级

这是网站在完成代码时所说的内容:





我还将标记的部分与以下内容交换:

  HTMLobjekt.innerText = 100 

  HTMLobjekt.innerText =100

  HTMLobjekt.Value = 100

但没有任何效果。

解决方案

在采取任何主动之前,您需要确保页面已满载。我检查了动态生成的一个这样的类的可用性 OrderBookPanel_text_33dbp 。然后我完成了你试图做的其余事情。最后,在将该金额放入占位符之前,您需要 Focus 目标。应用以上所有内容,您的脚本应该更像如下:

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

使用CreateObject(InternetExplorer.Application)
.Visible = True
.navigatehttps:/ /www.gdax.com/trade/LTC-EUR
而.Busy = True或.readyState< 4:DoEvents:Wend
设置HTML = .document

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

设置ival = HTML.querySelector([class ^ ='OrderForm_total_'])
[A1] = ival.innerText
.Quit
以$ b $结尾b结束子

此时输出:

  0.79139546 


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.

解决方案

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

Output at this moment:

0.79139546

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

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