【问题标题】:How to click button on IE page with VBA [duplicate]如何使用VBA单击IE页面上的按钮[重复]
【发布时间】:2019-10-21 12:23:12
【问题描述】:

我想在使用 VBA 时自动化一个重复的过程,我想点击网页上的一个按钮,但我似乎不知道怎么做,因为该按钮没有 ID。按钮的 html 代码在附加图像上以黄色突出显示。任何克服这一障碍的帮助将不胜感激。提前感谢

【问题讨论】:

  • 你能分享到目前为止你尝试了什么吗?
  • 我没有尝试太多,因为我不知道该怎么做。我是 VBA 和 HTML 的新手。到目前为止,我能够使用“getElementById”来获取元素名称并与之交互,但是在我没有 ID 的情况下我不知道该怎么做。跨度>

标签: html vba web-scraping automation


【解决方案1】:

试试GetElementsByTagName("button").item(X).click

其中X是页面设计中按钮元素的编号。

如果设计不是很稳定,你可以循环遍历按钮元素检查类名,然后单击具有 calss name = "" 的那个

Set ButtonsElement = IE.document.GetElementsByTagName("button")
For i = 1 To ButtonsElement.length - 1
    If ButtonsElement.item(i).className = "" Then
        ButtonsElement.item(i).click
        Exit For
    End if
Next

【讨论】:

    【解决方案2】:

    我会使用attribute = value 选择器,以运算符^ 开头,通过开头的子字符串来定位onclick 属性值,即SelectListControl_ShowPopup

    ie.document.querySelector("[onclick^='SelectListControl_ShowPopup']").click
    

    【讨论】:

      猜你喜欢
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2019-12-02
      • 1970-01-01
      相关资源
      最近更新 更多