【问题标题】:How to get elements that have no ID in VBScript如何在VBScript中获取没有ID的元素
【发布时间】:2012-03-30 09:12:18
【问题描述】:

我正在尝试编写一个脚本来驱动我的 IExplorer。在某种程度上它可以正常工作,但是我需要在textarea 中输入一个值,然后在它们都没有 ID 时单击一个按钮。我不知道如何使用 VBScript 在 HTML DOM 中移动,但有人建议在某处使用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>

它没有value属性,它的值是怎么输入的?

【问题讨论】:

  • 您可能使用的是 IE 8 或以前的版本。 IE DOM 不支持 getElementsByClassName()。请检查此 quirksmode.org/dom/w3c_core.html

标签: internet-explorer vbscript


【解决方案1】:
【解决方案2】:

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

试试下面的代码

  1. 检查类是否唯一

    .Document.getElementsByClassName("sB5 sPEB").Value = "southpark"
    

否则使用for循环和if语句发送值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 2012-03-07
    相关资源
    最近更新 更多