This is not the issue in this case. When the findElement command is issued, the error occurs whether the element is visible on the screen or not:
[HTTP] --> POST http://localhost:4723/session/ae0cc1ad-d4b0-4321-b3ea-b325a397ea5c/element
[HTTP] {"using":"id","value":"btnContinue"}
[AndroidUiautomator2Driver@d6bb (ae0cc1ad)] Driver proxy active, passing request on via HTTP proxy
[AndroidUiautomator2Driver@d6bb (ae0cc1ad)] Matched 'http://localhost:4723/session/ae0cc1ad-d4b0-4321-b3ea-b325a397ea5c/element' to command name 'findElement'
[AndroidUiautomator2Driver@d6bb (ae0cc1ad)] Proxying [POST http://localhost:4723/session/ae0cc1ad-d4b0-4321-b3ea-b325a397ea5c/element] to [POST http://127.0.0.1:8200/session/24f59b80-cfe3-485b-a679-782c323fe0f3/element] with body: {"using":"id","value":"btnContinue"}
[AndroidUiautomator2Driver@d6bb (ae0cc1ad)] Got response with status 400: {"sessionId":"24f59b80-cfe3-485b-a679-782c323fe0f3","value":{"error":"invalid argument","message":"java.lang.IllegalArgumentException: FindElementModel: The mandatory field 'selector' is not present in JSON","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidArgumentException: java.lang.IllegalArgumentException: FindElementModel: The mandatory field 'selector' is not present in JSON\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:65)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHa...
When comparing this with the Appium log on a build slave (which has no issues), I see the following:
2024-03-26 22:14:40:893 [HTTP] --> POST /session/548ee79c-475c-4f38-ae3b-43140e13a3e5/element
2024-03-26 22:14:40:894 [HTTP] {"using":"id","value":"btnContinue"}
2024-03-26 22:14:40:895 [AndroidUiautomator2Driver@8091 (548ee79c)] Calling AppiumDriver.findElement() with args: ["id","btnContinue","548ee79c-475c-4f38-ae3b-43140e13a3e5"]
2024-03-26 22:14:40:896 [AndroidUiautomator2Driver@8091 (548ee79c)] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
2024-03-26 22:14:40:896 [AndroidUiautomator2Driver@8091 (548ee79c)] Waiting up to 0 ms for condition
2024-03-26 22:14:40:897 [AndroidUiautomator2Driver@8091 (548ee79c)] Matched '/element' to command name 'findElement'
2024-03-26 22:14:40:898 [AndroidUiautomator2Driver@8091 (548ee79c)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/fd67a4cc-91df-47fc-a100-4188e5d2e3ba/element] with body: {"strategy":"id","selector":"btnContinue","context":"","multiple":false}
2024-03-26 22:14:40:941 [AndroidUiautomator2Driver@8091 (548ee79c)] Got response with status 200: {"sessionId":"fd67a4cc-91df-47fc-a100-4188e5d2e3ba","value":{"ELEMENT":"00000000-0000-0008-ffff-ffff00000042","element-6066-11e4-a52e-4f735466cecf":"00000000-0000-0008-ffff-ffff00000042"}}
2024-03-26 22:14:40:941 [AndroidUiautomator2Driver@8091 (548ee79c)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"00000000-0000-0008-ffff-ffff00000042","ELEMENT":"00000000-0000-0008-ffff-ffff00000042"}
The difference here is that on the build slave, the AppiumDriver is called:
2024-03-26 22:14:40:895 [AndroidUiautomator2Driver@8091 (548ee79c)] Calling AppiumDriver.findElement() with args: ["id","btnContinue","548ee79c-475c-4f38-ae3b-43140e13a3e5"]
Which actually modifies the json by adding/updating some keys in the JSON:
2024-03-26 22:14:40:898 [AndroidUiautomator2Driver@8091 (548ee79c)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/fd67a4cc-91df-47fc-a100-4188e5d2e3ba/element] with body: {"strategy":"id","selector":"btnContinue","context":"","multiple":false}
On my machine the AppiumDriver is not called and the JSON is proxied as-is:
[AndroidUiautomator2Driver@d6bb (ae0cc1ad)] Proxying [POST http://localhost:4723/session/ae0cc1ad-d4b0-4321-b3ea-b325a397ea5c/element] to [POST http://127.0.0.1:8200/session/24f59b80-cfe3-485b-a679-782c323fe0f3/element] with body: {"using":"[HTTP] --> POST http://localhost:4723/session/ae0cc1ad-d4b0-4321-b3ea-b325a397ea5c/element
[HTTP] {"using":"id","value":"btnContinue"}
The executed test and test environment is exactly the same on the build slave and on my machine. Appium version, driver version, test environment are also exactly the same.
The main difference is that the build slave is a Mac mini with an Intel processor and my own machine is a M3 pro MacBook.
When looking at the logs, I see some slight differences.
On the Intel Mac I see a POST request for the findElement as
[HTTP] --> POST /session/548ee79c-475c-4f38-ae3b-43140e13a3e5/element
[HTTP] {"using":"id","value":"btnContinue"}
On the M3 pro mac this looks like:
[HTTP] --> POST http://localhost:4723/session/ae0cc1ad-d4b0-4321-b3ea-b325a397ea5c/element
[HTTP] {"using":"id","value":"btnContinue"}
So currently I am trying to find out why on the m3 pro MacBook the findElement request is not forwarded to the AppiumDriver, but immediately proxied forward.