0

How to find the color of the button on wpf application using pywinauto tool?

Currently I am using pywinauto 0.6.3 for automating WPF application.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78

1 Answers1

1

Pywinauto does not support that, but you can get screen coordinates of element using rectangle() function and middle point using mid_point() (But in some cases in middle can be text). How to get color of some particular pixel you can check there.

For example:

from pywinauto import Desktop

def get_pixel_colour(point):
    import win32gui
    i_desktop_window_id = win32gui.GetDesktopWindow()
    i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id)
    long_colour = win32gui.GetPixel(i_desktop_window_dc, point.x, point.y)
    i_colour = int(long_colour)
    return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)

dlg = Desktop(backend="win32").window(title_re='YourAppTitle')
bt = dlg.Button
bt.set_focus()
print(get_pixel_colour(bt.rectangle().mid_point()))
Boris
  • 166
  • 2