Giter VIP home page Giter VIP logo

swapy's Introduction

Donate Join the chat at https://gitter.im/pywinauto/pywinauto Documentation Status Windows Tests Linux Tests codecov.io Code Health Codacy Badge Code Quality: Python Total Alerts

pywinauto

pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls, but it has support for more complex actions like getting text data.

Supported technologies under the hood: Win32 API (backend="win32"; used by default), MS UI Automation (backend="uia"). User input emulation modules mouse and keyboard work on both Windows and Linux.

Enjoying this?

Just star the repo or make a donation.

paypal

Your help is valuable since this is a hobby project for all of us: we do new features development during out-of-office hours.

  • In general the library tends to be cross-platform in the near future (Linux in 2018, macOS in 2019).
  • Reliable text based "record-replay" generator is also a high priority feature under development.
  • More feature requests and discusions are welcome in the issues.

Setup

  • run pip install -U pywinauto (dependencies will be installed automatically)

Documentation / Help

Simple Example

It is simple and the resulting scripts are very readable. How simple?

from pywinauto.application import Application
app = Application().start("notepad.exe")

app.UntitledNotepad.menu_select("Help->About Notepad")
app.AboutNotepad.OK.click()
app.UntitledNotepad.Edit.type_keys("pywinauto Works!", with_spaces = True)

MS UI Automation Example

More detailed example for explorer.exe:

from pywinauto import Desktop, Application

Application().start('explorer.exe "C:\\Program Files"')

# connect to another process spawned by explorer.exe
# Note: make sure the script is running as Administrator!
app = Application(backend="uia").connect(path="explorer.exe", title="Program Files")

app.ProgramFiles.set_focus()
common_files = app.ProgramFiles.ItemsView.get_item('Common Files')
common_files.right_click_input()
app.ContextMenu.Properties.invoke()

# this dialog is open in another process (Desktop object doesn't rely on any process id)
Properties = Desktop(backend='uia').Common_Files_Properties
Properties.print_control_identifiers()
Properties.Cancel.click()
Properties.wait_not('visible') # make sure the dialog is closed

Dependencies (if install manually)

  • Windows:
  • Linux:
  • Optional packages:
    • Install Pillow (by pip install -U Pillow) to be able to call capture_as_image() method for making a control's snapshot.

Packages required for running unit tests

Run all the tests: python ./pywinauto/unittests/testall.py

Contribution

Pull requests are very welcome. Read Contribution Guide for more details about unit tests, coding conventions, etc.

Copyrights

Pywinauto for native Windows GUI was initially written by Mark Mc Mahon. Mark brought many great ideas into the life using power of Python. Further contributors are inspired of the nice API so that the development continues.

Starting from 0.6.0 pywinauto is distributed under the BSD 3-clause license. Pywinauto 0.5.4 and before was distributed under the LGPL v2.1 or later.

  • (c) The Open Source Community, 2015-2018 (0.6.0+ development)
  • (c) Intel Corporation, 2015 (0.5.x maintenance)
  • (c) Michael Herrmann, 2012-2013 (0.4.2)
  • (c) Mark Mc Mahon, 2006-2010 (0.4.0 and before)

swapy's People

Contributors

moden-py avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swapy's Issues

Reuse `app` variable

Reuse app variable for one process owned different top level windows.
One app may be used for all windows owned by one process. For instance:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
notepad = app.Notepad
notepad.Wait('ready')
menu_item = notepad.MenuItem(u'&Help->&About Notepad')
menu_item.Click()
window = app.Dialog
window.Wait('ready')
button = window.OK
button.Click()

app.Kill_()

Now the same actions code looks:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
notepad = app.Notepad
notepad.Wait('ready')
menu_item = notepad.MenuItem(u'&Help->&About Notepad')
menu_item.Click()

app2 = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
window = app2.Dialog
window.Wait('ready')
button = window.OK
button.Click()
button.Click()

app2.Kill_()
app.Kill_()

Restarting the same application is probably not the thing you expect.

Real Time observation of the object

1. Select static object.
2. Start observation in a separate thread.
3. SWAPYs main window is minimized.

Observation (window?) should show log of object changes, which have been made 
with it by user.

It can be useful to investigate an object behavior while normal work.

Original issue reported on code.google.com by [email protected] on 16 Dec 2011 at 8:17

`app.dlg.ctrl.child_ctrl.Method()` fails

pywinauto support attribute/item access only for app, top_level_window. Filter children for such non top level window controls in SWAPY. Expect all the children are accessible from the top level window - app.dlg.child_ctrl.Method()

"CmnCtrl1.exe"

from pywinauto.application import Application

app_pwa_window1 = Application().Connect(title=u'Common Controls Sample', class_name='#32770')
pwa_window1 = app_pwa_window1.Dialog

treeview1 = pwa_window1.TreeView  # direct access works fine
print treeview1.handle in [i.handle for i in pwa_window1.Children()]
>>> True

object1 = pwa_window1['#32770']  # intermediate control
print treeview1.handle in [i.handle for i in object1.Children()]
>>> True

treeview1 = object1.TreeView  # access via an intermediate control does not

pwa_tree_item1 = treeview1.GetItem(['Birds'])
pwa_tree_item1.Expand()

Access name is not right

- SWAPY v. 0.4.1
- the app v. 2.2.9.6

Swapy shows the next access names:
['Static9',...]

But right is: 'Static6'

Note: print_control_identifiers() shows 'Static9' too.


Original issue reported on code.google.com by [email protected] on 30 May 2012 at 8:31

How to get refresh when pop up happens?

What steps will reproduce the problem?
1.
2.
3.


Please provide any additional information below.

Sometimes child windows or other windows pop up as a result of automated 
actions on a given window. Is there a way to refresh the main display to 
capture these newly created windows?

Thanks!



Original issue reported on code.google.com by [email protected] on 19 Mar 2012 at 3:32

  • Blocking: #23

test bug

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


Please use labels and text to provide additional information.


Original issue reported on code.google.com by [email protected] on 10 Dec 2011 at 8:45

  • Blocked on: #10

Code variable names improvements

The idea is to remove all unneeded from code.

  1. If we use only one application, just call it app and app2, app3 for others.
  2. The same for others.
  3. Remove pwa_ prefix. Now it used from a proxy class name if the shortest access name is not valid Python variable.

Regex for window titles

v. 0.4.2

If a window title has special symbols, find_windows do not work.


w_handle = pywinauto.findwindows.find_windows(title_re=u'Title(smth)', 
class_name='rctrl_renwnd32')[0]

Just change title_re= to title=

Original issue reported on code.google.com by [email protected] on 31 Jul 2012 at 7:07

Get stuck if Torrent Stream is running

What steps will reproduce the problem?
1. Run TS Player (VLC torrent stream)
2. Run SWAPY 

What is the expected output? What do you see instead?
SWAPY UI get comletely stuck. It unstuck just after process 'tsengine.exe' was 
killed.


Please use labels and text to provide additional information.
SWAPY v. 0.4.0-2
Windows XP 32bit SP3

Original issue reported on code.google.com by [email protected] on 14 Jul 2012 at 2:37

Start position

v.0.3.2

What is the expected output? What do you see instead?

Started not in the middle of the screen

Original issue reported on code.google.com by [email protected] on 11 Dec 2011 at 9:37

swapy windows 7/7x64 issue

What steps will reproduce the problem?
1. Run SWAPY

What is the expected output? What do you see instead?
No items in object list

What version of the product are you using? On what operating system?
swapy 0.4; Windows 7/7x64

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 10 Mar 2012 at 2:00

Attachments:

Add action - TypeKeys

It can be quite convenient to send keys to controls. Even for not text controls (to access the hotkey).
New extended action may be added to the Actions menu which open a sub window with editbox to make possible type commands.
Will post screenshots with the proposals in the near future that we can discuss.

Safe refresh

A lot of bugs/tasks depend on problem when the code generator counters is reset after a pywinauto object has been re-wrapped by SWAPY's proxy.
Although the code manger is a single tone object, but the code generator behavior is not. The counters are stored exactly with code generator behavior in a SWAPY wrapper.

Using `Application.Start` and/or `Application.Connect` is better in a code generator

When clicking on a top level window of an application SWAPY might suggest more menu items:

"Application.Start"
"Application.Connect"
----- (separator)
"Click"
... (other wrapper's methods)

It's not so hard to retrieve a process info using a top level window handle. Expected code for Start method:

app = Application.Start("user_software.exe") # even command line params could be retrieved

Preferable methods for Connect are listed by priority:

app = Application.Connect(path="user_software.exe")
app = Application.Connect(title="Software Title")
app = Application.Connect(pid=5349)

We can let user choose
which kind of Connect to use. :)

Like so:

"Application.Start"
"Application.Connect (by exe name)"
"Application.Connect (by title)"
"Application.Connect (by process id)"
----- (separator)
"Click"
... (other wrapper's methods)

I didn't say about launcher->worker case detection, but we may think about that as well.

Resizable UI

Object browser - 1/2 (left)
Editor - 1/4 (right, top)
Properties - 1/4 (right, bottom)


Original issue reported on code.google.com by [email protected] on 10 Dec 2011 at 8:50

App is not closed

What steps will reproduce the problem?
1. Refresh object browser
2. Select Swapy window
3. Simply close Swapy window

What do you see instead?
Console window is not closed.

Original issue reported on code.google.com by [email protected] on 16 Nov 2011 at 8:59

Object's icon

Add icons for all object types in the Objects browser.
For: Window, Static, Edit, etc.

Original issue reported on code.google.com by [email protected] on 10 Dec 2011 at 9:03

Delete/edit already generated commands

It would be helpful if there was a possibility to edit commands in the Editor window. Quite often I want to change or delete the generated commands. Maybe if not full edition but at least a kind of "undo" to remove last command and put another instead.

WPF support

What steps will reproduce the problem?
1. Open a WPF application 
2. Run Swapy 
3. WPF app is not listed

What is the expected output? What do you see instead?
APplication should be listed

What version of the product are you using? On what operating system?
0.4.3, Win 7, x86

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 8 Nov 2012 at 1:33

Not able to access menu bar items and Tool strip items

What steps will reproduce the problem?
1.In my application, I don't see the menu items such as File--saveas or file 
-->Exit. 
2.I am not able to access toolstrip items also
3.

What is the expected output? What do you see instead?
Should be able to access menu items and 

What version of the product are you using? On what operating system?

Windows 7
Please provide any additional information below.
Attached screensot


Original issue reported on code.google.com by [email protected] on 16 May 2013 at 4:20

Attachments:

Force action

If in some reason actions for concrete control are disabled (grayed), make 
possibility of force action.

Ctrl + grayed action


Original issue reported on code.google.com by [email protected] on 9 Oct 2012 at 7:07

`ctrl` variable is not assigned while generating click on toolbar button

It's reproduced on .\apps\MFC_samples\CmnCtrl1.exe. Just open "CToolBarCtrl" tab and run SWAPY.

Find "New" toolbar button and select Click method. The following code is generated:

import pywinauto

pwa_app = pywinauto.application.Application()
ctrl.Button(0).Click()

ctrl is not assigned here. Using ctrl.Button("New").Click() is also better than magic index.
Text property is absent at the toolbar button description pane.

v. 0.3

Features:
1. Objects Browser
2. Code editor
3. Browser --> Editor


Original issue reported on code.google.com by [email protected] on 7 Apr 2011 at 6:37

  • Blocked on: #2

Add ListBox wrapper

pywinauto can deal with a ListBox - pywinauto.controls.win32_controls.ListBoxWrapper,
but SWAPY see only texts of the ListBox items.
Regular wrapper should be added.

Do not confuse with the pywinauto.controls.common_controls.ListViewWrapper.

Long names in properties viewer

When I click to copy a long value, I get it cut.

Example text:
Access names : ['Static21', 
u'\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 
\u0437\u043e\u043d\u044b - \u044d\u0442\u043e 
\u0430\u0434\u0440\u0435\u0441\u0430, 
\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 
\u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0432\u0430\u0448\u0435\u0439 
\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 
\u0441\u0435\u0442\u0438, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 
\u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0442\u044c\u0441\u044f \u0441 \u04

Original issue reported on code.google.com by [email protected] on 14 Jun 2012 at 1:51

Change obj_actions finding

try:
        obj_actions = dir(pywin_obj.WrapperObject())
    except:
        obj_actions = dir(pywin_obj)

Object type handling needed.

Original issue reported on code.google.com by [email protected] on 17 Oct 2011 at 4:24

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.