在没有id的网站上点击搜索按钮

时间:2016-09-28 13:22:13

标签: vba excel-vba dom excel

我正在组建一个VBA,它会将公司名称搜索到一个网站并进行搜索。 问题是我似乎无法使用我的代码来点击搜索按钮

代码:

Sub SearchBot()

    Dim objIE As InternetExplorer
    Dim aEle As HTMLLinkElement
    Dim y As Integer
    Dim result As String

    Set objIE = New InternetExplorer
    objIE.Visible = True
    objIE.navigate "https://website.com"
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
    objIE.document.getElementById("SearchTopBar").Value = Sheets("Sheet1").Range("A2").Value

    'click the 'go' button; This line below is what is causing the problem
    objIE.document.getElementByClassName("iPadHack Tmbsearchright").Click

    ' this line is what the button in the website is referencing
    'a class="iPadHack tmbsearchright"onclick="document.forms['hello2'].submit();"> </a

    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

1 个答案:

答案 0 :(得分:0)

知道了!多谢你们。对于那些好奇的人,我用过:

<div class="input-group" id="other-education">
  <p class="subtitleDirection">Please list in chronological order, any additional cources beyond the degree(s) listed above, including any Ministry of Education Courses. If you have not completed any additional course work, please indicate.</p>
  <div class="clearFix"></div>
  <label id="otherEducation">Additional Courses*</label>
  <div id="otherEducationHistory">
    <input type="text" class="three-lines" name="otherUniversity_1" placeholder="Institution" onblur="this.placeholder='Institution'" onfocus="this.placeholder=''" />
    <input type="text" class="three-lines" name="otherDegree_1" placeholder="Degree/Diploma" onblur="this.placeholder='Degree/Diploma'" />
    <input type="date" class="three-lines" name="otherEducationYear_1" />
    <input type="button" value="+" onclick=addOtherEducation() />
  </div>
  <!--end of otherEducationHistory div-->

  <div class="clearFix"></div>
</div>
<!--end of other-education div-->

<p id="noAdditionalCourseWork">I have not completed any additional course work.</p>
<input type="radio" name="checkNo" id="checkNo" onclick="hideCourseWork()" />
<br />
<p id="undoNoAdditionalCourseWork" onclick="reAddCourseWork()">(Undo).</p>