如何在VBScript中获取没有ID的元素

时间:2012-03-30 09:12:18

标签: internet-explorer vbscript

我正在尝试编写一个脚本来驱动我的IExplorer。它可以正常工作但我需要在textarea中输入一个值,然后单击一个按钮,同时它们都没有ID。我不知道如何使用VBScript在HTML DOM中移动arround,但有人建议在某处以某种方式使用document.all。我也在考虑使用JS脚本为它们提供ID,然后返回并使用document.getElementbyid但我不知道如何在VBScript中运行带有初始化文档对象的JS脚本。到目前为止我所拥有的是:

Option Explicit
With CreateObject("InternetExplorer.Application")
  .Visible = True
  .Navigate "https://adwords.google.co.uk/um/Logout"
  Do While .Busy
WScript.Sleep 100
  Loop
  .Document.getElementByID("Email").Value = "testtestingtton@gmail.com"
  .Document.getElementByID("Passwd").Value = "PWD"
  'Note: You could just get the form and submit it, but
  'you'll miss out on any special JavaScript associated 
  'with the Submit button.
  .Document.getElementByID("signIn").Click
  Do While .Busy
    WScript.Sleep 100
  Loop
      .Navigate "https://adwords.google.co.uk/o/Targeting/Explorer?"
        Do While .Busy
    WScript.Sleep 100
  Loop
'here begins the problem'
  .Document.All.tags("sB5 sPEB").Value = "southpark"
  '.Document.getElementsByTagName("sJ1").Click'

End With

此外,由于我要填写的字段是

<textarea style="overflow-y: hidden; height: 36px;" class="sB5 sPEB"></textarea>

它没有值属性它的值是如何输入的?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

而不是使用.Document.All.tags("sB5 sPEB").Value = "southpark"

尝试以下代码

  1. 检查班级是否唯一

    .Document.getElementsByClassName("sB5 sPEB").Value = "southpark"
    
  2. 否则使用for循环和if语句发送值

相关问题