daveenguyen / atomacos

Automated Testing on macOS
https://daveenguyen.github.io/atomacos/
GNU General Public License v2.0
48 stars 13 forks source link

looking to set selectedchildren attribute #13

Open jbflow opened 4 years ago

jbflow commented 4 years ago

Trying to figure out how to set the selectedchildren attribute of an object.

I know in Obj-C it's AXUIElementSetAttributeValue, but can't figure out how to do it with this.

jbflow commented 4 years ago

OK I figured it out - using setattr ('AXSelectedChildren', AXUIElement.ref)

Don't know if that's the best way but it works.

daveenguyen commented 4 years ago

Try using x.AXSelectedChildren = AXUIElement.ref

__setattr__ is supposed to be called when you try do to that. python docs

__setattr__ definition checks if it's an AX attribute https://github.com/daveenguyen/atomacos/blob/master/atomacos/_a11y.py#L82

jbflow commented 4 years ago

Yeah that was the first thing I tried, I thought that was the case but for some reason it doesn't work. No error or anything, it appears to work, but doesn't do what is expected in the GUI. I was really trying to understand the functioning by looking at ApplicationServices and seeing what I needed to pass to AXUIElementSetAttributeValue when I came across this and thought I'd try it. I wasn't really expecting it to work tbh.

jbflow commented 4 years ago

OK it was my mistake, I needed to do it like this x.AXSelectedChildren = [AXUIElement.ref]

and also I have to use a direct reference to the AXUIElement, when it's stored in a variable it doesn't work.

jbflow commented 4 years ago

So if I store the list of AXChildren as a variable and then try to set AXSelectedChildren from that list using the index it just doesn't do anything, it has to be set from the original element and AXChildren[x].ref. I guess that's something to do with how the Accessibility stuff works?

daveenguyen commented 4 years ago

I think as long as value you give is a CFTypeRef based on the apple docs. Not sure what makes something CFTypeRef. Probably something that comes from objc library calls. .ref are original reference to objects from objc, I believe.

https://github.com/daveenguyen/atomacos/blob/master/atomacos/_a11y.py#L259 https://github.com/daveenguyen/atomacos/blob/d520135ff03ba548140dec07bd1b4ef2a2ae0e5c/atomacos/_macos.py#L142

https://developer.apple.com/documentation/applicationservices/1460434-axuielementsetattributevalue?language=objc