html - 使用vba在html输入框中输入文本

标签 html vba

我正在尝试使用 VBA 将一个值输入到 Internet Explorer 页面上的 from 中。我看过类似的帖子,但似乎无法查明我的问题。我对 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="">

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

    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

名称“user_number.1.number_1”我认为是 html 中唯一可以用来找到这个输入框的元素,每次打开网页时 ID 都会改变。 我如何才能在此字段中输入值?

谢谢!

最佳答案

如 sid 所述,您有一个额外的“=”符号。

替换

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

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

这只是我的想法,没有经过测试的代码。如果这不起作用,请将上面代码中的 (0) 替换为 (1)

如果页面上没有其他同名元素,那么这将起作用。 否则将上述语句中的(0)替换为适当的序号位置。

关于html - 使用vba在html输入框中输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20611714/

相关文章:

javascript - jquery 无法读取我的 css 属性的值

html - 显示 :inline-block blocks word-wrap:break-word

javascript - Github 如何隐藏垃圾邮件机器人的电子邮件

javascript - 从本地文件访问 localStorage

vba - 我的用户定义函数是否正确以及如何在 Excel 中使用它?

html - PDF报告生成

vba - 使用 instr 获取两个文本的完全匹配

excel - 从 Excel 中的文本单元格中提取 URL

arrays - 在Excel VBA中将字节数组写入范围而不循环

excel - Module1 中的 VBA 组合框值