Summary
Android emulators and real devices come with their default versions of Chrome, which can be automated with Appium and ChromeDriver. But if you’ve been using the latest Chrome browsers on your real devices or the latest Android Emulators (Android 9 and above) you might have seen the following error in your script. Especially when you are using the FindById-locator strategy to find elements in your Chrome browser and or Webview of your Hybrid app.
This is due to the fact that Chrome now uses the W3C protocol to communicate.
Since the W3C Specification process is focused on being economical, and because id and class name can both be easily written as CSS or XPath, they were removed from the specification but Appium does not do the necessary translation of said commands.
Fix: There are 2 options:
- Add the capability “goog:chromeOptions” with the option “w3c” set to “false”
- Change all you FindByID-selectors to FindByCSS-selectors
We recommend going for option two, as this will ensure that your code is ready for Selenium 4 and beyond.
Here is a before and after screenshot of a code sample to demonstrate how this was fixed.