AppiumForMac xpath is not detecting elements for Desktop Application MacOS

I am Automating MacOS native applications using AppiumForMac (Thanks Stuart Russell for the tool). It was working fine with xpath. But now its failing to detect he element by xpath probably with latest Appium-Python-Client.
Does anyone have solution on this ?
Here is code snippet for Python:

from appium import webdriver

Options are available in Python client since v2.6.0

from appium.options.mac import Mac2Options
from appium.webdriver.common.appiumby import AppiumBy

options = Mac2Options()
options.bundle_id = ‘com.apple.TextEdit’

The default URL is http://127.0.0.1:4723/wd/hub in Appium1

drv = webdriver.Remote(‘http://127.0.0.1:4723’, options=options)
xpath = “/AXApplication[@AXTitle=‘TextEdit’]/AXWindow[@AXTitle=‘Untitled’ and @AXIdentifier=’_NS:34’ and @AXSubrole=‘AXStandardWindow’]/AXScrollArea[@AXIdentifier=’_NS:8’]/AXTextArea[@AXIdentifier=‘First Text View’]”

#edit_field = drv.find_element(by=AppiumBy.CLASS_NAME, value=‘XCUIElementTypeTextView’)
edit_field = drv.find_element(by=AppiumBy.XPATH, value=xpath)
edit_field.send_keys(‘hello world’)

AppiumForMac has not been supported for some years. Consider migrating to appium-mac2-driver instead.

Hi @mykola-mokhnach,
Thanks for help.
I have installed AppiumForMac for recording xpath from here
https://github.com/appium/appium-for-mac/releases/download/v0.4.1/AppiumForMac.zip

Can you please give me the new version (appium-mac2-driver) tool’s address ?
I have installed “appium driver install mac2” from here


Is it same that you are mentioning ?
If yes then how to record xpath using this ?

Test examples are inside https://github.com/appium/appium-mac2-driver/blob/master/test/functional/find-e2e-specs.js

Thank you @Aleksei for the suggestion.
My problem is how to record xpath (for example in line number 83 in script shared by you).
Because the one I recorded with AppiumForMac(version 1), is not working. The element is not found.
How are you recording the xpath.

Unfortunately there is no recording tool available for the Mac2 driver. You could potentially use Xcode UI Test Recorder for such purpose, although it would still require some skill to translate the script generated by this tool into the one compatible for this driver.

Hi @mykola-mokhnach Thanks a lot for the article link:
https://smartbear.com/blog/the-basics-of-xcuitest-and-using-xcode-ui-test/
I am able to find the element successfully with relative xpath !
There is another problem:
Click is not working on element “XCUIElementTypeButton”.

function used:
driver.find_element(by=AppiumBy.XPATH, value=’//XCUIElementTypeButton[@elementType=“9” and @label=“Sign in”]’).click()

Here is python error trace:

Traceback (most recent call last):
File “/Users/saurabhkoli/Documents/Appium_MacOS_Automation/MacOS_Apps_Automation/TestAppiumMac/Test_AppiumMac.py”, line 44, in
sign_in_element.click()
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py”, line 94, in click
self._execute(Command.CLICK_ELEMENT)
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py”, line 395, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py”, line 345, in execute
self.error_handler.check_response(response)
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/appium/webdriver/errorhandler.py”, line 122, in check_response
raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace))
selenium.common.exceptions.WebDriverException: Message: Could not proxy command to the remote server. Original error: timeout of 240000ms exceeded
Stacktrace:
ProxyRequestError: Could not proxy command to the remote server. Original error: timeout of 240000ms exceeded
at WDAMacProxy.proxy (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:280:13)
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
at ProtocolConverter.convertAndProxy (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/jsonwp-proxy/protocol-converter.js:266:12)
at WDAMacProxy.proxyCommand (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:336:12)
at WDAMacProxy.proxyCommand (/Users/saurabhkoli/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:60:12)
at WDAMacProxy.proxyReqRes (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:410:32)

Here is Appium Log:

[debug] [Mac2Driver@d4f6 (9e40b50b)] Responding to client with driver.findElement() result: {“element-6066-11e4-a52e-4f735466cecf”:“DE589B18-D0BE-4F5F-94ED-1E7531CA68F3”,“ELEMENT”:“DE589B18-D0BE-4F5F-94ED-1E7531CA68F3”}
[HTTP] <-- POST /session/9e40b50b-902a-4f3b-ab74-791ad1aaa10e/element 200 340 ms - 137
[HTTP]
[HTTP] --> POST /session/9e40b50b-902a-4f3b-ab74-791ad1aaa10e/element/54D86FA4-6AAF-420E-92A4-57ED2A4E56D2/click
[HTTP] {“id”:“54D86FA4-6AAF-420E-92A4-57ED2A4E56D2”}
[Mac2Driver@d4f6 (9e40b50b)] Driver proxy active, passing request on via HTTP proxy
[debug] [WD Proxy] Matched ‘/session/9e40b50b-902a-4f3b-ab74-791ad1aaa10e/element/54D86FA4-6AAF-420E-92A4-57ED2A4E56D2/click’ to command name ‘click’
[debug] [WD Proxy] Proxying [POST /session/9e40b50b-902a-4f3b-ab74-791ad1aaa10e/element/54D86FA4-6AAF-420E-92A4-57ED2A4E56D2/click] to [POST http://127.0.0.1:10100/session/F5B5E3B4-34E1-42AD-ABA5-BC0EC99CF4EE/element/54D86FA4-6AAF-420E-92A4-57ED2A4E56D2/click] with body: {“id”:“54D86FA4-6AAF-420E-92A4-57ED2A4E56D2”}
[WD Proxy] AxiosError: timeout of 240000ms exceeded
[WD Proxy] at RedirectableRequest.handleRequestTimeout (/opt/homebrew/lib/node_modules/appium/node_modules/axios/lib/adapters/http.js:628:16)
[WD Proxy] at RedirectableRequest.emit (node:events:514:28)
[WD Proxy] at Timeout. (/opt/homebrew/lib/node_modules/appium/node_modules/follow-redirects/index.js:169:12)
[WD Proxy] at listOnTimeout (node:internal/timers:573:17)
[WD Proxy] at processTimers (node:internal/timers:514:7)
[HTTP] <-- POST /session/9e40b50b-902a-4f3b-ab74-791ad1aaa10e/element/54D86FA4-6AAF-420E-92A4-57ED2A4E56D2/click 400 240071 ms - 1112
[HTTP]

-----------------------------

Also the send_keys is not working with XCUIElementTypeTextField even after finding the element successfully.
Please let me know if there is any other way to use it.

this looks like an issue with the xctest. Try to enable the showServerLogs capability and check what is in the logs.