单击一个按钮

时间:2017-02-16 00:11:13

标签: vba dom

如何编写代码以点击“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

标签名称是空白的,因为我尝试了很多东西而且没有一个工作。

1 个答案:

答案 0 :(得分: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

如果您想选择li下的第二个navigation,可以使用:nth-child选择器:

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