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

浏览器自动化导航:如何点击网页中的‘Search by Parcel Number’按钮?

如何自动化点击「按包裹号搜索」按钮

你的现有脚本通过输入文本再回车的方式依赖浏览器查找功能,容易受页面布局、输入法状态或重复文本影响,稳定性不足。以下是几种更可靠的自动化点击方案:

方案1:AutoHotkey控件直接点击

用AutoHotkey自带的Window Spy工具获取按钮的控件标识(比如ClassNN或文本),然后直接调用ControlClick:

; 先激活目标浏览器窗口(替换为你的浏览器实际标题)
WinActivate, 印第安纳波利斯政府网站 - Chrome
Sleep 500
; 直接点击对应按钮,文本匹配需准确
ControlClick, Search by Parcel Number, 印第安纳波利斯政府网站 - Chrome

方案2:AutoHotkey结合浏览器COM接口操作DOM

通过浏览器的自动化接口直接定位元素,避免依赖界面布局:

; Chrome示例(需确保Chrome支持自动化)
chrome := ComObjCreate("Chrome.Application")
chrome.Visible := true
chrome.Navigate("https://www.indy.gov/workflow/property-taxes")
; 等待页面加载完成
While chrome.Busy || chrome.ReadyState != 4
    Sleep 100
; 通过文本定位按钮并点击
button := chrome.Document.querySelector("a:contains('Search by Parcel Number')")
button.Click()
; 可选:验证按钮是否变为激活状态
if (button.className = "Active")
    MsgBox 按钮已成功激活

方案3:Python Selenium跨浏览器方案

如果用Selenium,定位和点击逻辑更清晰,还能直接验证状态:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.indy.gov/workflow/property-taxes")
; 等待按钮可点击,超时10秒
button = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.LINK_TEXT, "Search by Parcel Number"))
)
button.click()
; 验证按钮class是否变为Active
assert "Active" in button.get_attribute("class"), "按钮未成功激活"

内容的提问来源于stack exchange,提问作者john denver abella

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 19:45:49