Javascript and UI automation with Appium


I’m trying to get the currently selected button within a UIASegmented control.

I’ve found out ,through the iOS dev library, that the UIASegementedControl has a method that returns the selected button - (UIAElement) selectedButton()

I’m trying to use this method to get the button via ExecuteScript, and I can locate the segmented control on appium inspector with:

I’m new to all this, and assumed that adding .selectedButton() to the end of that, and passing via ExecuteScript() would let me get the button, but I get an error saying UIAElementNil is not a function. I’m not quite sure where to go with this. Am I completely wrong in the way I’m doing it?