You can use the search() function to find elements with certain properties and that might return a different element from the one you imagine.
When selecting through the UI, always the leaf elements (the lowest one in the tree branch with no children) are selected. Depending on where the model comes from, those might be Solid/Body elements and not the Component/Part they belong to. It's similar to how things are in manufacturing softwares like Inventor or Fusion 360: there are components/parts and they contain one or more solid bodies with the actual geometry.
Elements at different levels of the branch (Component vs Body) have different properties, so depending on what properties you are using for the search, it might not return the leaf element, but one of its parents. In case of the model shown in the topmost picture, only the Component has the "Component Name" property, and only the Body has the "Appearance" property. So if you search for "Component Name", you'll get back a Component and not a Body.
Note: a component may have multiple bodies
However, depending on what you want to do with the element you found, it might make no difference if you found the Component or the Body. E.g. if I use the isolate() function it produces pretty much the same result (apart from a different element being selected in the Structure Browser):
If you need to, you can of course walk up and down the tree branch to get from a Body to a Component or vice-versa - see enumNodeChildren() and getNodeParentId()