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

Selenium VBA定位WebElement失败求助:NoSuchElementError

Selenium VBA 无法定位网页元素问题求助

我尝试使用Selenium VBA填充网页元素,但始终无法定位到目标元素。以下是我的代码:

Dim driver As New webdriver

driver.Start "Chrome"
driver.get "https://example.com"

'driver.FindElementByClass("gn_sdm_header_background").FindElementByName("searchKey").SendKeys ("abcd")
'driver.FindElementByCss("#gobtnDiv > form > table > tbody > tr > td:nth-child(3) > input[type=text]").SendKeys ("abcd")
'driver.FindElementByXPath("//*[@id=""gobtnDiv""]/form/table/tbody/tr/td[3]/input").SendKeys ("abcd")

End Sub

上述三行定位代码均返回NoSuchElementError,对应未找到的元素分别是:

  • 第一行:class 为 gn_sdm_header_background 的元素
  • 第二行:CSS 选择器 #gobtnDiv > form > table > tbody > tr > td:nth-child(3) > input[type=text] 对应的元素
  • 第三行:XPath //*[@id="gobtnDiv"]/form/table/tbody/tr/td[3]/input 对应的元素

目标元素的参数信息见元素检查截图。

恳请各位提供解决方案!


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 05:05:32