如何使用VBA在IE页面上单击按钮

时间:2019-06-06 01:17:30

标签: html vba web-scraping automation

我想在使用VBA时使重复过程自动化,并且我想单击网页上的一个按钮,但由于按钮没有ID,所以我似乎不知道该怎么做。该按钮的html代码在随附的图像上以黄色突出显示。克服这一障碍的任何帮助将不胜感激。预先感谢enter image description here

2 个答案:

答案 0 :(得分:0)

尝试GetElementsByTagName("button").item(X).click

X是页面设计中按钮元素的编号。

如果设计不是很稳定,则可以遍历按钮元素,检查类名,然后单击具有calss name =“”的类。

Set ButtonsElement = IE.document.GetElementsByTagName("button")
For i = 1 To ButtonsElement.length - 1
    If ButtonsElement.item(i).className = "" Then
        ButtonsElement.item(i).click
        Exit For
    End if
Next

答案 1 :(得分:0)

我将使用一个以运算符^开头的attribute = value选择器,以开头的子字符串(即SelectListControl_ShowPopup)为onclick属性值定位。

ie.document.querySelector("[onclick^='SelectListControl_ShowPopup']").click