Vba 点击按钮
我如何编写代码来点击按钮“Catálogo” 按钮和HTML代码图像: 到目前为止,我的代码是:Vba 点击按钮,vba,dom,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("InternetEx
'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
标记名为空,因为我尝试了很多方法,但没有一种有效。相关元素实际上不是a或an,而是元素或锚元素 请记住,
getElementsByTagName
将返回页面中的所有a
元素;您可能只需要一个特定的元素
如果您安装了IE11,您可以通过传入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
Set elem = .querySelector("#etpa-iframe > html > body > store-manager > div > side-bar > div > navigation > ul > li:nth-child(2) > a")
如果要选择
导航下的第二个li
,可以使用选择器:
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
Set elem = .querySelector("#etpa-iframe > html > body > store-manager > div > side-bar > div > navigation > ul > li:nth-child(2) > a")
您的问题是不知道将什么传递到getElementsByTagName
?还是别的什么?请澄清您的问题。它返回错误“424”-需要对象,您知道原因吗?我注意到它在html标记之前有一个#文档,而且它必须在第一个标记a处完成,它位于第二个标记li内,正如您所提到的,它位于ul内,因此代码将继续作为…导航>ul>li>a。我怎么提到这个职位?我尝试了.queryselectoral(“”)(I)的组合,但没有成功。“谢谢你的帮助,泽夫·斯皮茨。”拉斐尔·科斯塔更新。