How to handle dynamically changing UIElements in atomac/python?

416 views Asked by At

I am knew to atomac UI automation tool, I am trying to access a button in my mac app and every time app loads buttons UIElement tree is changing because of which I am not able to re use in my code, below is my code

allButtons= allUIElement[5].findAllR(AXRole='AXButton')
print allButtons
position = allButtons[1].AXPosition
print position
size = allButtons[1].AXSize
print size
clickpoint = ((position[0] + size[0] / 2), (position[1] + size[1] / 2))
print clickpoint
test20Window.clickMouseButtonLeft(clickpoint)

As you can see in my code I am trying to access button from UIElement[5] which will dynamically change to say 6,7 or 1 when the app loads next time because of which the button which i want it to click is not happening

1

There are 1 answers

0
user7592290 On

I see that you asked the question a while ago, but I hope this helps:

your_app = atomac.getAppRefByLocalizedName("Your App Name")
app_window = your_app.windows()[0]
buttons = app_window.findAllR(AXRole='AXButton')
your_button = buttons[0]
button_position = your_button.AXPosition
button_size = your_button.AXSize
clickpoint = ((button_position[0] + button_size[0] / 2), (button_position[1] + button_size[1] / 2))
your_button.clickMouseButtonLeft(clickpoint)

This way you find your application window dynamically.