Javascript 未能单击intranet网页上的第二个按钮

Javascript 未能单击intranet网页上的第二个按钮,javascript,html,css,vba,Javascript,Html,Css,Vba,除了type、value和onclick之外,它没有id元素进入第二个按钮元素 下面是我的webUI代码 <input type="button" value="Download" onclick="javascript:__doPostBack('GridView1','Account_number$0')"> Dim htmlDoc As HTMLDocument Dim MyBrowser As InternetExplorer Dim MyHTML_Element

除了type、value和onclick之外,它没有id元素进入第二个按钮元素

下面是我的webUI代码

<input type="button" value="Download" 
onclick="javascript:__doPostBack('GridView1','Account_number$0')">
Dim htmlDoc As HTMLDocument  
Dim MyBrowser As InternetExplorer  
Dim MyHTML_Element As IHTMLElement  
Dim myURL As String  

On Error GoTo Err_Clear  
myURL = "url......................."  
Set MyBrowser = New InternetExplorer  
MyBrowser.Silent = True  
MyBrowser.Navigate myURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set htmlDoc = MyBrowser.Document

htmlDoc.all.txtAccNo.Value = "0" & "" & TextBox2.Value 
htmlDoc.all.ddlReasons.Value = "1"
htmlDoc.all.txtRequester.Value = TextBox3.Text 'Enter your password here
htmlDoc.all.txtMobNo.Value = "0" & "" & TextBox1.Value
htmlDoc.all.txtLandLine.Value = ""
htmlDoc.all.txtEmailAdd.Value = Range("E15")
htmlDoc.all.ddlRelation.Value = "3"
htmlDoc.all.button1.Click
第二个按钮的吹扫脚本出错

htmlDoc.getElementsByXpath("input[type=""button""]").Click

请帮助我,如何自动执行此按钮?

当我遇到此问题时,我会尝试为正在讨论的elm找到唯一的属性。原因是页面上可能有其他按钮您不想单击。看起来
onclick
value
对于下载按钮是唯一的。我选择了
value
。这里有一个单独的函数(为了清楚起见),应该可以工作。它应该单击找到的第一个下载按钮。通过修改函数,可以将其设置为单击特定行的按钮

Function ClickDownload(doc As IHTMLDocument) As Long
  On Error GoTo ErrHandler
  Dim elms As IHTMLElementCollection
  Dim elm As IHTMLElement

  Set elms = doc.getElementsByTagName("input") 'gather all input elms
  For Each elm In elms 'book through each input elm until we find a match
    If elm.Value = "Download" Then 'the elm.value "Download" seems unique enough
      elm.Click
      GoTo ErrHandler 'jump out, and be sure to set vars to nothing
    End If
  Next

ErrHandler:
  Set elm = Nothing
  Set elms = Nothing
  ClickDownload = err.Number 'silently return 0 if it did not fail
End Function

当我遇到这个问题时,我试图为正在讨论的榆树找到一个独特的属性。原因是页面上可能有其他按钮您不想单击。看起来
onclick
value
对于下载按钮是唯一的。我选择了
value
。这里有一个单独的函数(为了清楚起见),应该可以工作。它应该单击找到的第一个下载按钮。通过修改函数,可以将其设置为单击特定行的按钮

Function ClickDownload(doc As IHTMLDocument) As Long
  On Error GoTo ErrHandler
  Dim elms As IHTMLElementCollection
  Dim elm As IHTMLElement

  Set elms = doc.getElementsByTagName("input") 'gather all input elms
  For Each elm In elms 'book through each input elm until we find a match
    If elm.Value = "Download" Then 'the elm.value "Download" seems unique enough
      elm.Click
      GoTo ErrHandler 'jump out, and be sure to set vars to nothing
    End If
  Next

ErrHandler:
  Set elm = Nothing
  Set elms = Nothing
  ClickDownload = err.Number 'silently return 0 if it did not fail
End Function

不响应您的代码:(htmlDoc.getElementsByPath(“输入[type=”“button”“]”)(0)。单击不响应您的代码:(htmlDoc.getElementsByPath(“输入[type=”“button”“]”)(0)。单击查找属性表示感谢,但在第二个按钮上仍不响应注意:单击第一个按钮“查看账单”时加载下载按钮需要时间np.这听起来像是一个单独的问题,但我要说的是,处理加载时间可能会变得复杂。引入ie对象WithEvents,并使用DocumentComplete()的URL、StatusTextChange()的文本、表单计时器来调用布尔函数,该函数会在页面完成之前查找特定元素(足够了)。很幸运找到了一个属性,但在第二个按钮上仍然没有响应注意:当单击第一个按钮“查看账单”np时,加载下载按钮需要时间。这听起来像是一个单独的问题,但我要说的是,处理加载时间可能会变得复杂。使用ie对象WithEvents,并使用DocumentComplete()进行处理的URL、StatusTextChange()的文本、窗体计时器,用于调用布尔函数,该函数在您删除页面以使其完整(足够)之前查找要存在的特定元素。祝您好运