点击一个按钮 [英] Click in a button

查看:74
本文介绍了点击一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写代码以单击该按钮Catálogo?

How do I write the code to click in that button "Catálogo"?

按钮和HTML代码图像:

Button and HTML Code Image:

到目前为止我的代码:

'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

标记名称为空,因为我尝试了很多事情,但没有一个起作用。

The tag name is blank because I tried lots of things and none of them worked.

推荐答案

相关元素实际上不是 button <输入类型=按钮/> ,而是 a 元素或 anchor元素

The relevant element is not actually a button or an <input type=button/>, but rather an a element, or anchor element.

请记住, getElementsByTagName 将返回所有 a 元素页面中的内容;您可能只需要特定的元素。

Keep in mind that getElementsByTagName will return all the a elements in the page; you probably only want a specific element.

如果安装了IE11,则可以致电 querySelector ,传入CSS选择器:

If you have IE11 installed, you can call querySelector, passing in a CSS selector:

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 导航,您可以使用 :nth-​​child 选择器:


If you want to select the second li under the navigation, you can use the :nth-child selector:

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

这篇关于点击一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆