pywinauto icon indicating copy to clipboard operation
pywinauto copied to clipboard

.click_input() coordination bug using rectangle().top or bottom

Open meshuggahtas opened this issue 6 years ago • 4 comments

Using .click_input() with a .rectangle()'s top or bottom erroneously uses a higher value.

This only happens with click_input. I've noted (after reading the docs) that click_input() is similar to mouse.click() while the simple click() is doing some WM_* messages. Unfortunately there are elements I can't click reliable using a WindowSpec().click() in my automated app (focus problem on the automated app's side, unrelated to pywinauto).

Version used: 0.6.4

Example code using notepad:

import pywinauto
from pywinauto import actionlogger, mouse

pywinauto.actionlogger.enable()

APP = pywinauto.Application(backend="win32").start("notepad.exe")

APP.Notepad.maximize()
elem = APP.Notepad.Edit
print(elem.rectangle())

mouse.click(coords=(elem.rectangle().left + 1, elem.rectangle().top + 1), button="left")
elem.click(coords=(elem.rectangle().left + 1, elem.rectangle().top + 1), button="left")
elem.click_input(coords=(elem.rectangle().left + 1, elem.rectangle().top + 1), button="left")

mouse.click(coords=(elem.rectangle().right + 1, elem.rectangle().bottom + 1), button="left")
elem.click(coords=(elem.rectangle().right + 1, elem.rectangle().bottom + 1), button="left")
elem.click_input(coords=(elem.rectangle().right + 1, elem.rectangle().bottom + 1), button="left")

Result:

2018-08-10 15:45:18,487 INFO: Started notepad.exe application.
(L0, T43, R1920, B1080)
2018-08-10 15:45:18,498 INFO: Maximized window "Névtelen - Jegyzettömb"
2018-08-10 15:45:18,773 INFO: Clicked Edit "" by left button event (1, 44)
2018-08-10 15:45:19,192 INFO: Clicked Edit "" by left button mouse click at (1, 87)
2018-08-10 15:46:26,383 INFO: Clicked Edit "" by left button event (1921, 1081)
2018-08-10 15:46:26,817 INFO: Clicked Edit "" by left button mouse click at (1921, 1124)

1,44 and 1921, 1081 is correct. 1,87 and 1921, 1124 is not correct.

meshuggahtas avatar Aug 10 '18 14:08 meshuggahtas

The defenition of click_input()

def click_input(
        self,
        button = "left",
        coords = (None, None),
        button_down = True,
        button_up = True,
        double = False,
        wheel_dist = 0,
        use_log = True,
        pressed = "",
        absolute = False,
        key_down = True,
        key_up = True)

In your case was

realtive_coords = (1, 44)
top_left_corner_coords = (0, 43)
result = (1, 87)

just use

elem.click_input(coords=(elem.rectangle().left + 1, elem.rectangle().top + 1), button="left", absolute = True)

@vasily-v-ryabov bug?

drinkertea avatar Oct 29 '18 20:10 drinkertea

@drinkertea I'm not sure what I'm supposed to see, but your line also won't work, it clicks to 1920,1080.

pywinauto 0.6.5 (release)

Starting position: (L0, T43, R1920, B1080)

Code:

import pywinauto
from pywinauto import actionlogger, mouse

pywinauto.actionlogger.enable()

APP = pywinauto.Application(backend="win32").start("notepad.exe")

APP.Notepad.maximize()
elem = APP.Notepad.Edit
print(elem.rectangle())
elem.click_input(coords=(elem.rectangle().left + 1, elem.rectangle().top + 1), button="left", absolute = True)
elem.click_input(coords=(elem.rectangle().right, elem.rectangle().bottom), button="left", absolute = True)

Result:

click_input without absolute = True:

2018-10-31 12:44:17,829 INFO: Clicked Edit "" by left button mouse click at (1, 44) 2018-10-31 12:44:18,431 INFO: Clicked Edit "" by left button mouse click at (1920, 1080)

click_input with absolute = True:

2018-10-31 12:46:54,811 INFO: Clicked Edit "" by left button mouse click at (1, 44) 2018-10-31 12:46:55,397 INFO: Clicked Edit "" by left button mouse click at (1920, 1080)

meshuggahtas avatar Oct 31 '18 11:10 meshuggahtas

1,44 and 1921, 1081 is correct. 1,87 and 1921, 1124 is not correct.

i run the script on the latest pywinauto and results are different

click_input without absolute = True:

(L0, T43, R1920, B1040) 2018-10-31 22:19:29,030 INFO: Clicked Edit "" by left button mouse click at (1, 87) 2018-10-31 22:19:29,601 INFO: Clicked Edit "" by left button mouse click at (1920, 1083)

click_input with absolute = True:

(L0, T43, R1920, B1040) 2018-10-31 22:20:52,980 INFO: Clicked Edit "" by left button mouse click at (1, 44) 2018-10-31 22:20:53,569 INFO: Clicked Edit "" by left button mouse click at (1920, 1040)

drinkertea avatar Oct 31 '18 19:10 drinkertea

Pywinauto 0.6.6: click_input with absolute=False seems like not pressing at the right location...?

  • My monitor resolution is 1920x1080
  • Notepad.Edit location is right below the menu bar (0, 46) and the scrollbar is part of it
  • Output of my example https://github.com/pywinauto/pywinauto/issues/540#issuecomment-434658145

absolute=False

(L0, T43, R1920, B1080) 2019-03-05 11:03:36,445 INFO: Clicked Edit "" by left button mouse click at (1, 87) 2019-03-05 11:03:37,018 INFO: Clicked Edit "" by left button mouse click at (1920, 1123)

absolute=True

(L0, T43, R1920, B1080) 2019-03-05 11:04:58,546 INFO: Clicked Edit "" by left button mouse click at (1, 44) 2019-03-05 11:04:59,124 INFO: Clicked Edit "" by left button mouse click at (1920, 1080)

meshuggahtas avatar Mar 05 '19 10:03 meshuggahtas