2016-09-28 65 views
0

我正在組織一個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 
+0

儘量只使用一個類,像Tmbsearchright –

+0

只是去嘗試,並沒有奏效。 我得到了錯誤: 「運行時錯誤438: 對象不支持此屬性或方法」 – Sameer

+0

使2號線:'設置oNode = objIE.document.getElementsByClassName( 「Tmbsearchright」)(0 )'和'oNode.click'。請注意,'.getElementByClassName'是錯誤的語法。或者你可以嘗試另一種方式:'設置oForm = document.forms.item(「hello2」)'和'oForm.submit' – omegastripes

回答

0

明白了!多謝你們。對於那些好奇,我用:

set oNode = objIE.document.getElementsbyClassName("iPadHack tbmsearchright")(0) 
oNode.click