Appium with Python(Hybrid App): Locator Strategy 'css selector' is not supported for this session error for find_element_by_id, after running the script using 'py.test'

Hi,
Finding element by id shows error, if I run the script using ‘py.test’. The issue occurs in Hybrid app only. Kindly guide me to resolve it.

Info::
IDE: Pycharm community edition
Appium version: 1.17.1
Appium Python Client: 1.0.1
Selenium: 3.141.0
Pytest: 5.4.3
Mobile OS: Android 10.3.4
PC OS: Windows 10

Steps:

  1. Call capabilities from ‘conftest’
  2. Run pasted code below using ‘py.test’

Code:
import pytest

@pytest.mark.usefixtures("setup")
class TestEc1():
    def test_ec1_action(self):
        self.driver.find_element_by_id("com.androidsample.generalstore:id/radioFemale").click()

Logs - Appium server
[HTTP] --> POST /wd/hub/session/67cd55d3-4b8f-4b1e-8da5-f8e0cc838dd0/element
[HTTP] {“using”:“css selector”,“value”:"[id=“com.androidsample.generalstore:id/radioFemale”]"}
[W3C (67cd55d3)] Calling AppiumDriver.findElement() with args: [“css selector”,"[id=“com.androidsample.generalstore:id/radioFemale”]",“67cd55d3-4b8f-4b1e-8da5-f8e0cc838dd0”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[W3C (67cd55d3)] Encountered internal error running command: InvalidSelectorError: Locator Strategy ‘css selector’ is not supported for this session
[W3C (67cd55d3)] at AndroidUiautomator2Driver.validateLocatorStrategy (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js:388:13)
[W3C (67cd55d3)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:31:8)
[W3C (67cd55d3)] at AndroidUiautomator2Driver.findElement (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:53:21)
[W3C (67cd55d3)] at commandExecutor (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js:330:9)
[W3C (67cd55d3)] at C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\async-lock\lib\index.js:125:12
[W3C (67cd55d3)] at AsyncLock._promiseTry (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\async-lock\lib\index.js:249:31)
[W3C (67cd55d3)] at exec (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\async-lock\lib\index.js:124:9)
[W3C (67cd55d3)] at AsyncLock.acquire (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\async-lock\lib\index.js:140:3)
[W3C (67cd55d3)] at AndroidUiautomator2Driver.executeCommand (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js:343:39)
[W3C (67cd55d3)] at AppiumDriver.executeCommand (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\lib\appium.js:534:36)
[W3C (67cd55d3)] at runMicrotasks ()
[W3C (67cd55d3)] at processTicksAndRejections (internal/process/task_queues.js:85:5)
[W3C (67cd55d3)] at asyncHandler (C:\Users\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:309:21)
[HTTP] <-- POST /wd/hub/session/67cd55d3-4b8f-4b1e-8da5-f8e0cc838dd0/element 400 9 ms - 2370
Logs - Pytest:

    C:\Users\PycharmProjects\Ecommerce\test>py.test test_ec1.py -v -s
======================================================================================= test session starts ========================================================================================
platform win32 -- Python 3.7.7, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- c:\users\appdata\local\programs\python\python37\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.7.7', 'Platform': 'Windows-10-10.0.17763-SP0', 'Packages': {'pytest': '5.4.3', 'py': '1.8.1', 'pluggy': '0.13.1'}, 'Plugins': {'forked': '1.1.3', 'html': '2.1.1', 'metadata': '1.9.0', 'variables': '1.9.0', 'xdist': '1.32.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk-11.0.1'}
rootdir: C:\Users\PycharmProjects\Ecommerce\test
plugins: forked-1.1.3, html-2.1.1, metadata-1.9.0, variables-1.9.0, xdist-1.32.0
collected 1 item

test_ec1.py::TestEc1::test_ec1_action FAILED
============================================================================================= FAILURES =============================================================================================
_____________________________________________________________________________________ TestEc1.test_ec1_action ______________________________________________________________________________________

self = <test.test_ec1.TestEc1 object at 0x0000018A7473F648>

    def test_ec1_action(self):
>       self.driver.find_element_by_id("com.androidsample.generalstore:id/radioFemale").click()

test_ec1.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\..\appdata\local\programs\python\python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:360: in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
..\..\..\appdata\local\programs\python\python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:978: in find_element
    'value': value})['value']
..\..\..\appdata\local\programs\python\python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
    self.error_handler.check_response(response)
..\..\..\AppData\Roaming\Python\Python37\site-packages\appium\webdriver\errorhandler.py:29: in check_response
    raise wde
..\..\..\AppData\Roaming\Python\Python37\site-packages\appium\webdriver\errorhandler.py:24: in check_response
    super(MobileErrorHandler, self).check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <appium.webdriver.errorhandler.MobileErrorHandler object at 0x0000018A7476A848>
response = {'status': 400, 'value': '{"value":{"error":"invalid selector","message":"Locator Strategy \'css selector\' is not sup...s\\\\app\\\\node_modules\\\\appium\\\\node_modules\\\\appium-base-driver\\\\lib\\\\protocol\\\\protocol.js:309:21)"}}'}

Found a workaround:
Downgrade selenium version to 3.3.1 by pip install selenium==3.3.1 which removes ‘css selector’ error. (issue persists above V3.3.1)

Still we need a proper solution for this issue as while installation of downgraded Version, it shows message stating "ERROR: appium-python-client 0.52 has requirement selenium<4,>=3.14.1, but you'll have selenium 3.3.1 which is incompatible."

Please let me know if someone could find the solution

Best regards!