Search code examples
pythonpywinauto

Scrolling issues with pywinauto


I'm trying to scroll in an excel document (using pywinauto) and it doesn't seem to work.

Code:

app = Application(backend="uia").connect(process=8876)
win = app.top_window()
win.set_focus()
win.wheel_mouse_input(wheel_dist=10)

The set_focus works but the scrolling doesn't, I also tried playing with the wheel_dist with no success.

Another question, Is there a way to scroll Right/Left?

Thanks.


Solution

  • I solved it by using pywinauto.mouse directly instead of using wheel_mouse_input through the window object. I also needed to find the right coords. So this is the new code:

    app = Application(backend="uia").connect(process=8876)
    win = app.top_window()
    win.set_focus()
    win_rect = win.rectangle()
    coords = (random.randint(win_rect.left, win_rect.right), random.randint(win_rect.top, win_rect.bottom))
    pywinauto.mouse.scroll(coords=coords, wheel_dist=10)
    

    I solved the "right/left scrolling" by using the pyautogui library which has a function for this, called hscroll:

    pyautogui.hscroll(10) 
    

    I didn't find something similar in pywinauto