使用vba将文本输入到html输入框中

use*_*346 7 html vba

我正在尝试使用VBA在Internet Explorer页面上输入一个值.我看过类似的帖子,但似乎无法确定我的问题.我对VBA有点流利,但HTML对我来说是新的.每次加载页面时,我访问的网页上的ID属性都会发生变化.以下是我尝试访问的HTML元素的镜头:

<input type="text" size="20" style="text-align: right; width: 261px;" autocomplete="off"    id="ext-comp-1067" name="user_numbers.1.number_1" class="x-form-text x-form-field x-form- num-field" title="">
Run Code Online (Sandbox Code Playgroud)

我目前使用的代码在这里:

    Sub OpenWebPage()

    Dim ObjCollection As Object
   Dim i As Long
Dim objElement As Object
Dim doc As Object
Dim form As Object



    Dim ie As Object
    Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
    ie.Navigate "http://11.182.123.21/#!/view/dashboards/dashboard-1"
    ie.Visible = True
    While ie.Busy
        DoEvents
   Wend


    Application.Wait Now + TimeValue("00:00:10")

 Set ObjCollection = ie.Document.getElementsByName("user_numbers.1.number_1").Value = "123"

End sub
Run Code Online (Sandbox Code Playgroud)

名称"user_number.1.number_1"我认为是html中唯一可用于查找此输入框的元素,每次打开网页时ID都会更改.如何在此字段中输入值?

谢谢!

Pra*_*mar 5

正如sid所提到的,你有一个额外的"="符号.

更换

Set ObjCollection = ie.Document.getElementsByName("user_numbers.1.number_1").Value = "123"
Run Code Online (Sandbox Code Playgroud)

同

ie.Document.getElementsByName("user_numbers.1.number_1")(0).Value = "123"
Run Code Online (Sandbox Code Playgroud)

这只是我的头脑而不是测试代码.如果这不起作用(0),请在上面的代码中替换(1).

如果页面上没有其他元素具有相同的名称,那么这将起作用.否则(0)在上述声明中用适当的序号替换.