clojureselenium-chromedriver

google chrome driver findElement not working on M1?


We use google chrome driver in our selenium tests (language clojure).

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

However, I got the error

java.lang.IllegalArgumentException: No matching field found: findElement for class org.openqa.selenium.By$ById
    at clojure.lang.Reflector.getInstanceField(Reflector.java:271)
    at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:315)
    at com.my.company$connect$fn__15343.invoke(selenium.clj:50)
    at com.my.company.selenium$connect.invokeStatic(selenium.clj:49)
    at com.my.company.selenium$connect.invoke(selenium.clj:29)

Note that this issue seems only occur on Mac chips as far as I know, cause my teammates who got a intel processor doesn't see the error.


Solution

  • The code doesn't make much sense.

    The -> threading macro doesn't care what the contents of the next form - it just puts its arguments into each other, one by one. So it doesn't care that you use (try (...)) and want to put that driver inside those (...) - it will still put it at the second position so that it becomes (try driver (...)).

    That means that you end up calling (.findElement ...) directly on the result of (By/id ...), and that's why you see that error.

    You need to change the code so that it becomes (.findElement driver ...).