【问题标题】:Can i click on a button by de href or the class?我可以点击 de href 或类的按钮吗?
【发布时间】:2016-06-11 01:38:28
【问题描述】:

我目前正在尝试单击一个按钮,但它没有 id 或类名,只有类和 href。

html代码为:

<a href="#" class="bt-acessar-login radius" onclick="validarFornecedor()" ;="">
  <i></i>
  <span>Acessar sistema</span>
  <div class="clear"></div>
 </a>

而我试过的vba代码是:

Set btnObject = .document.getElementByClass("bt-acessar-login radius")
btnObject.FireEvent ("onclick")

【问题讨论】:

  • getElementByClass 不是一个东西 - 你的意思是 getElementsByClassName 吗?另外 - 实际方法返回一个集合,而不是单个元素,所以你需要类似btnObject(0).FireEvent ("onclick")
  • 其实我只是试了一下getElementByClass,现在我把代码改成:Set elems = .document.getElementsByClassName("bt-acessar-login radius")`For Each e In elems`If (e.getAttribute("onclick") = "validarFornecedor()") Thene.SetFocuse.Click Exit ForEnd IfNext e

标签: html vba class internet-explorer href


【解决方案1】:

我再搜索一些,找到适合我的代码!

Set elems = .document.getElementsByClassName("bt-acessar-login radius")
        For Each e In elems
        If (e.getAttribute("onclick") = "validarFornecedor()") Then
            e.Focus
            e.Click
            Exit For
        End If
        Next e

【讨论】:

    猜你喜欢
    • 2021-09-28
    • 2020-11-09
    • 2021-09-20
    • 1970-01-01
    • 2014-04-18
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多