You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何点击无ID网页按钮?点击时报错‘Object doesn't support this property or method’求助

解决VBA点击网页按钮报错“Object doesn't support this property or method”的问题

Hey there, let's fix this issue step by step!

First, let's pinpoint the root cause: your current code is trying to click the <i> icon element, but this element doesn't have a Click method. The actual clickable interactive control is its parent <button> tag that wraps the icon.

Problem Code Analysis

This line in your code is the culprit:

ie.document.getElementsByClassName("button-icon right-offset-5 sp-i-xls-download-grey").Click

getElementsByClassName returns a collection of <i> elements with those class names, and directly calling .Click on this collection (or the element itself) fails because <i> isn't a clickable control.

Fix Solutions

Here are two reliable ways to resolve this:

Method 1: Target the outer <button> directly

Use querySelector with CSS selectors to precisely locate the button containing your target icon:

Sub test()
 Dim ie As Object
 Set ie = New InternetExplorer
 ie.navigate "http://www.spark-interfax.ru/system/home/card#/company/3411D127F25A45F7ABAB32964A32848D/427"
 ie.Visible = True
 ' Wait for full page load
 While ie.Busy Or ie.readyState < 4: DoEvents: Wend
 ' Optional: Add extra wait for element rendering (avoids race conditions)
 Application.Wait Now + TimeValue("00:00:02")
 
 ' Locate button using CSS selector (targets button with the icon inside)
 ie.document.querySelector("button.js-not-print:has(.sp-i-xls-download-grey)").Click
End Sub

If your IE version doesn't support the :has pseudo-class, use this more basic selector instead:

ie.document.querySelector("button.btn-default.btn-sm.js-not-print").Click

Method 2: Find the <i> element, then click its parent button

If you prefer sticking with getElementsByClassName, first grab the icon element, then navigate to its parent button to trigger the click:

Sub test()
 Dim ie As Object
 Dim iconElement As Object
 Set ie = New InternetExplorer
 ie.navigate "http://www.spark-interfax.ru/system/home/card#/company/3411D127F25A45F7ABAB32964A32848D/427"
 ie.Visible = True
 While ie.Busy Or ie.readyState < 4: DoEvents: Wend
 Application.Wait Now + TimeValue("00:00:02")
 
 ' Get the first matching icon element
 Set iconElement = ie.document.getElementsByClassName("button-icon right-offset-5 sp-i-xls-download-grey")(0)
 ' Click its parent button element
 iconElement.parentElement.Click
End Sub

Extra Tips

  • Sometimes the page finishes loading but elements aren't fully rendered yet. Adding a short wait or a loop to check if the element exists before interacting can prevent unexpected errors.
  • When using getElementsByClassName, always specify an index (like (0)) to target a single element—otherwise you'll get errors trying to operate on a collection instead of an individual element.

内容的提问来源于stack exchange,提问作者Bimka09

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:33:28