首页 > 解决方案 > Vba自动化单击此脚本中的“输入”按钮

问题描述

我一直在尝试单击 GPS Vizualizer 上的此按钮但没有成功,我尝试了几种方法,包括在设置我的暗淡等和设置到文档之后..;没有成功,我错过了什么,谁能帮忙,谢谢

With doc.all("input")
    .focus
    .OnClick
End With

HTML:

<input style="font-weight: bold; margin-bottom: 3px;" 
  onclick="this.form.action='http://www.gpsvisualizer.com/map?output_geocoder'; document.map_form.special.value='geocoder'; this.form.submit();" 
   type="button" value="Draw a map">

标签: vbaautomation

解决方案


尝试:

.document.querySelector("input[onclick*='this.form.action']")

CSS 查询

它使用 的.querySelector方法document来应用一个 css 选择器,该选择器查找input包含属性的标签onclick,其中包含字符串'this.form.action'

您还可以使用:

doc.getElementsByTagName("input")(8).Click

以下工作:

Option Explicit

Public Sub GetInfo()
    Dim IE As New InternetExplorer

    With IE
        .Visible = True
        .navigate "http://www.gpsvisualizer.com/geocoder/"

        While .Busy Or .readyState < 4: DoEvents: Wend
        .document.querySelector("input[onclick*='this.form.action']").Click
       ' .document.getElementsByTagName("input")(8).Click

       Stop '<==Delete me
        .Quit
    End With
End Sub

推荐阅读