2017-02-16 225 views
0

如何編寫代碼點擊該按鈕「Catálogo」?點擊按鈕

按鈕和HTML程序代碼映像:

到目前爲止我的代碼:

'This will load a webpage in IE 
Dim i As Long 
Dim URL As String 
Dim IE As Object 
Dim objElement As Object 
Dim objCollection As Object 

'Create InternetExplorer Object 
Set IE = CreateObject("InternetExplorer.Application") 

'Set IE.Visible = True to make IE visible, or False for IE to run in the background 
IE.Visible = True 

'Define URL 
URL = "https://www.wix.com/my-account/sites/0761466b-a270-4ab2-a3b3-e7498df11329/app/1380b703-ce81-ff05-f115-39571d94dfcd?referralInfo=DA_Wix%20Stores" 

'Navigate to URL 
IE.navigate URL 

' Statusbar let's user know website is loading 
Application.StatusBar = URL & " is loading. Please wait..." 

' Wait while IE loading... 
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop) 
Do While IE.readyState = 4: DoEvents: Loop 'Do While 
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until 

'Webpage Loaded 
Application.StatusBar = URL & " Loaded" 

'Unload IE 
Set objElement = Nothing 
Set objCollection = Nothing 

'Click on desired button 
With IE.document 
    Set elems = .getElementsByTagName(" ") 
      elems.Click 
End With 

標籤名稱爲空白,因爲我嘗試過很多事情,沒有他們的工作。

+0

是你的問題,你不知道要傳入'getElementsByTagName'什麼?或者是其他東西?請澄清你的問題。 –

回答

0

相關的元素實際上不是button<input type=button/>,而是一個a元素,或錨元素

請注意,getElementsByTagName將返回頁面中的所有a元素;你可能只想要一個特定的元素。

如果您已經安裝IE11,你可以打電話querySelector,傳遞一個CSS選擇器:

With IE.document 
    Dim elem As Object 
    Set elem = .querySelector("#etpa-iframe > html > body > store-manager > div > side-bar > div > navigation > ul") 
    elem.click 
End With 

如果你想選擇第二linavigation,您可以使用:nth-child選擇:

Set elem = .querySelector("#etpa-iframe > html > body > store-manager > div > side-bar > div > navigation > ul > li:nth-child(2) > a") 
+0

它返回錯誤「424」 - 需要對象,你知道爲什麼嗎? 我注意到它在html標記之前有一個#document,並且它必須在第一個標記a處完成,它位於第二個標記li中,它位於ul內部,因此代碼將繼續如下所示...導航> ul> li> a。我如何提到這個位置?我嘗試了.queryselectorall(「」)(i)的組合,但沒有奏效。 謝謝你的幫助Zev Spitz。 –

+0

@RafaelCosta更新時間 –