I came here struggling to understand how UI Automation scripting works, as the documentation and example code out there is really lacking (or written from a very specific point of view that doesn't explain all cases).
Here are two things on the subject I learned:
- First and foremost, you must enable Accessibility on the element. I had disabled it in my trials and things were behaving very strangely until I re-enabled it (getting a similar "unexpected error" as you). So make sure you have Accessibility turned on. But note that some things still work with it disabled. For example, you can still look up the element by its name (accessibilityIdentifier), but you won't be able to tap it or call
setValue()
.
- You have to dig through your application hierarchy. My assumption was that giving an element an
accessibilityIdentifier
would allow me to simply look up the element with that identifier like HTML's getElementById
. But it is not like this at all. You have to dig through your hierarchy level by level, even when using an accessibilityIdentifier. Luckily you can use UIAElement.logElementTree()
to get some clues as to the correct hierarchy to use.
So far I am NOT at all impressed with this framework, but I am ever so slowly making progress.