question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

target position is wrong for _perform_click in some cases

See original GitHub issue

Expected Behavior

pywinauto.controls.hwndwrapper._perform_click should simulate the click behavior correctly.

Actual Behavior

when the “Dispaly -> Scale and layout -> Change the size of text, apps and other items” setting for windows 10 OS is NOT 100%, the target position of pywinauto.controls.hwndwrapper._perform_click may need to be adjusted according to the scale ratio.

Steps to Reproduce the Problem

  1. set “dispaly -> scale and layout -> change the size of text, apps and other items” to be 200%

  2. use pywinauto with win32 backend to get an item from a SysTreeView32 control in an app ,and then call the click() method for this item

Short Example of Code to Demonstrate the Problem

            tree_view = app.top_window().child_window(
                control_id=129, class_name="SysTreeView32"
            )
            target_item = tree_view.wrapper_object().get_item(['query','target'])
            target_item.click()

A raw method to solve this problem

  1. add import win32print into hwndwrapper.py

  2. insert the following code into pywinauto.controls.hwndwrapper._perform_click near line 1663 in hwndwrapper.py

    scale_ratio = win32print.GetDeviceCaps(win32gui.GetDC(ctrl.handle), win32con.LOGPIXELSX) / 96
    if scale_ratio != 1.0:
        coords = [int(item*scale_ratio) for item in coords]

after

    if absolute:
        coords = ctrl.client_to_screen(coords)

Relevent Problem

pywinauto.mouse._perform_click_input may also need to be adjusted.

Specifications

  • Pywinauto version: 0.6.8
  • Python version and bitness: 3.7
  • Platform and OS: windows 10

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
nixgnefcommented, May 8, 2020

@airelil I’ve found addtional docs relevent to this issue:

  1. DWM scaling
  2. High DPI Settings in Windows

This issue may be caused by a setting in which the coordinates got from the API and the coordinates displayed do not match(differ by the scale ratio). To figure out the exact way to get the right coordinates in different situations is cumbersome, a simple way to handle this issue is to add extra parameters to let the user to decide whether to make an adjustment and the scale ratio to adjust the coordinates。 Finally, people who use pywinauto include me should thank you contributors of this project. 😃

1reaction
nixgnefcommented, Jun 7, 2020

okay… it cost me one day to figure out why _listview_item.click() chooses wrong item… 😦

I also spent a little time to find the real cause,so I opened this issue to remind other users。

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Espresso: PerformException - java - Stack Overflow
I've run into the error Animations or transitions are enabled on the target device several times. In the latest case, the real problem...
Read more >
Crash with mindate #522 - wdullaer/MaterialDateTimePicker
If we set a minimum date and try a quick moving datepiker, in some cases an arrow ... IllegalArgumentException: Invalid target position at ......
Read more >
Espresso basics - Android Developers
When you have found a suitable matcher for the target view, it is possible to perform instances of ViewAction on it using the...
Read more >
Espresso – Testing RecyclerViews at Specific Positions
An alternative is to use the findViewHolderForAdapterPosition(int position) method to locate the view (by way of its ViewHolder ) for a specific ...
Read more >
Event Handling Basics - Apple Developer
Introduces event mechanisms and the types of events in Cocoa and describes how to handle events of each type.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found