在 Python + Appium 於 Android 環境下執行測試時,拋出 WebDriverException: Message: Invalid locator strategy: css selector。環境變數已檢查無誤。
Appium 的 UiAutomator2 驅動程式預設不支援 CSS Selector 定位策略,僅支援 XPath、ID、Accessibility ID、Class Name 等原生定位方式。此錯誤常見於 Appium 版本升級或驅動程式變更後。
find_element_by_css_selector 改為 find_element_by_xpath 或 AppiumBy.ID 等。appium-css-selector 外掛,但增加維護成本。https://stackoverflow.com/questions/31679588/how-do-i-fix-error-invalid-locator-strategy-css-selector
優先使用 AppiumBy.ACCESSIBILITY_ID 或 AppiumBy.ID,穩定性最高;必要時使用 XPath,避免依賴 CSS Selector。