Element's snapshot depth

My goal is to get minimum required snapshot depth for each test. To achieve this i try to get depth for each element used in the test. I tried accessing parents until they exist with:

let depth = 0;
let element = await client.$(selector);
while (element) {
    depth += 1;
    try {
        element = await element.$("..");
    } catch (_) {
        break;
    }
}

but it doesn’t work.
Is there any other option besides getting source at each step and analyzing it?

Edit:
I want it to work with every selector type (not just xpath).
For element.parentElement(); I get: Method is not implemented.

I assume such possibilty would only exist for UIA2 driver with limitXPathContextScope setting set to false

Thank you for your response. Sadly it still doesn’t work.
My config is:

const client = await remote({
    path: "/",
    port: 4723,
    capabilities: {
        platformName: 'iOS', 
        'appium:deviceName': "...", 
        'appium:platformVersion': '15.8',
        'appium:automationName': 'XCUITest', 
        "appium:udid": "...",
        "appium:webDriverAgentUrl": "http://localhost:7700",
        "appium:settings": {
            "limitXPathContextScope": false,
        }
    },
});

My test:

const child = await client.$('//*[@name="Start"]');
console.log({ child });
const parent = await element.$("..");
console.log({ parent });

Child element exists and is nested. Parent element gets NoSuchElementError.

Edit:
I also tried:

const parent = await element.$("./..");
    'appium:automationName': 'XCUITest',

¯_(ツ)_/¯

Did not see that, my bad.
Are there any alternative methods for determining depth on iOS, besides bisection, that are compatible with all types of selectors?