Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying to use uiautomator modules #316

Open
skempegouda opened this issue Aug 17, 2022 · 1 comment
Open

Error while trying to use uiautomator modules #316

skempegouda opened this issue Aug 17, 2022 · 1 comment

Comments

@skempegouda
Copy link

..\conftest.py:9: in test_setup
d.demo.close_all()
......\lib\demo.py:412: in close_all
self.device.press.recent()
........\venv\lib\site-packages\uiautomator_init_.py:74: in call
return self.func(*args, **kwargs)
........\venv\lib\site-packages\uiautomator_init_.py:787: in press
return self.server.jsonrpc.pressKey(str(key))
........\venv\lib\site-packages\uiautomator_init
.py:421: in wrapper
return method_obj(*args, **kwargs)
........\venv\lib\site-packages\uiautomator_init
.py:132: in call
"%s: %s" % (jsonresult["error"]["data"]["exceptionTypeName"], jsonresult["error"]["message"])
E TypeError: string indices must be integers

@unofficialdxnny
Copy link

It looks like the error is happening because the code is trying to treat a string as if it were a dictionary. Specifically, when it tries to access jsonresult["error"]["data"]["exceptionTypeName"], it's expecting jsonresult["error"]["data"] to be a dictionary, but it's actually a string. That's why we're getting the "string indices must be integers" error. We need to add a check to make sure we're dealing with a dictionary before trying to access keys like that.

Here's the code to check if jsonresult["error"]["data"] is a dictionary before accessing its keys:

if isinstance(jsonresult["error"]["data"], dict):
    exception_type = jsonresult["error"]["data"].get("exceptionTypeName", "UnknownException")
else:
    exception_type = "UnknownException"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants