Getting Attribute Values of UI Elements in Another App Using Swift3?
Getting Attribute Values of UI Elements in Another App Using Swift3?
- Subject: Getting Attribute Values of UI Elements in Another App Using Swift3?
- From: James Lee <email@hidden>
- Date: Sun, 27 Nov 2016 14:46:50 -0500
Hi All,
I also posted this on Stack Overflow if someone wants to answer there as
well.
http://stackoverflow.com/questions/40784738
I'm trying to get the title attribute of each ui elements inside a
window using the following function.
func AXUIElementCopyAttributeValue(_ element: AXUIElement, _
attribute: CFString, _ value: UnsafeMutablePointer<CFTypeRef?>) -> AXError
I can get the AXChildren using AXUIElementCopyAttributeValue, but the
function returns an error when I try to get AXTitle. Also, I added xCode
in the privacy system preference under the accessibility. Could someone
tell me the right way to get the attribute values of UI Elements in
swift3? If there's a better or another way to access attributes of ui
elements in another application without using AX Api, I'd also like to
learn. Anyways, here's my code.
var children:CFTypeRef?
var error = AXUIElementCopyAttributeValue((windows?[0])!,
"AXChildren" as CFString, &children)
if error == .success, let elements = children as? [AXUIElement] {
for element in elements {
var cfName:CFTypeRef?
error = AXUIElementCopyAttributeValue((element), "AXTitle"
as CFString, &cfName)
if error == .success {
let axValue = cfName as! AXValue
let type = AXValueGetType(axValue)
var attribute = ""
var attributePtr =
UnsafeMutableRawPointer(Unmanaged<AnyObject>.passUnretained(attribute as
AnyObject).toOpaque())
AXValueGetValue(cfName as! AXValue, type, &attributePtr)
attribute =
Unmanaged<AnyObject>.fromOpaque(attributePtr).takeUnretainedValue() as!
String
print("\(attribute)")
} else {
NSLog("\(error)")
}
}
}
I also tried
if error == .success, let name = cfName as? String {
print(name)
}
Thank you so much!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden