【问题标题】:Use VBA code to click on a button on webpage使用 VBA 代码单击网页上的按钮
【发布时间】:2011-01-23 07:34:35
【问题描述】:

我正在编辑一个 vba 程序,并希望对 vba 进行编码以单击网页中的按钮。按钮的html是:

<input type="image" src="/lihtml/test_button3.gif" align="left" alt="File_Certificate_Go"/>

我想我必须为 getElementBy 设置一个变量???然后是 variable.click,但我不知道如何准确获取元素(因为它没有名称或 id,而且我不能给它一个,因为它不是我的网页)。

非常感谢任何帮助!

【问题讨论】:

    标签: html vba click webpage


    【解决方案1】:

    也许是这样的:

    Set tags = wb.Document.GetElementsByTagname("Input")
    
    For Each tagx In tags
        If tagx.alt = "File_Certificate_Go" Then
            tagx.Click
        End If
    Next
    

    其中 wb 是 WebBrowser 控件。

    【讨论】:

      【解决方案2】:

      你不能给元素一个 id 有什么原因吗?

      即:

      <input id='myButton' type=image src="/lihtml/test_button3.gif" align=left alt=File_Certificate_Go> 
      

      然后:

      document.getElementById('myButton').click()
      

      编辑:根据您的评论,您必须抓取页面上的所有输入元素,然后循环浏览它们以寻找使您的输入独一无二的元素:

      var elms = document.getElementsByTagName("input"); 
      for (var i=0; i< elms.length; i++) 
          if(elms[i].src = '/lihtml/test_button3.gif') { elms[i].click(); }
      

      反正都是这样的

      【讨论】:

      • 我无法更改 html,因为它不是我的网页。
      猜你喜欢
      • 2021-12-16
      • 2016-03-13
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 1970-01-01
      相关资源
      最近更新 更多