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

M1芯片Mac设备上ChromeDriver的findElement调用报错问题咨询

解决M1 Mac上Clojure+Selenium调用findElement的IllegalArgumentException问题

问题根源

你的代码存在两个关键错误:

  1. ->宏用法错误:错误地将driver传递给try块,导致后续方法调用没有使用到WebDriver实例;
  2. 方法调用对象错误:在By/id返回的org.openqa.selenium.By$ById实例上调用findElement,但这个类不存在该方法——findElement是WebDriver实例的方法,参数才是By定位器。

M1芯片Mac的Java环境反射校验更严格,直接抛出了错误;而Intel设备可能因JVM隐式处理或版本差异没有触发报错,但代码本身是错误的。

修正后的代码

调整->宏的作用范围,确保findElement由driver调用:

(try
  (-> driver
      (.findElement (By/id "my-text-input")))
  (catch Exception ex
    (log/errorf ex " error caught!!")))

或者不用宏,直接显式调用:

(try
  (.findElement driver (By/id "my-text-input"))
  (catch Exception ex
    (log/errorf ex " error caught!!")))

验证逻辑

修正后,代码会正确调用WebDriver的findElement方法,传入By定位器,无论M1还是Intel设备都能正常执行,不会再抛出No matching field found: findElement的异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 17:05:07