Skip to content Skip to sidebar Skip to footer

Automation Microsoft Sql Server 2008 R2 Using Python(pywinauto)

I am creating Microsoft SQL Server Management Studio Automation tool using python. The problem is I can't select the Child_tree(Northwind) database It's selecting the Parent_tree(D

Solution 1:

As I could understand in comments, you need waiting until main window is open after login.

window = pwa_app.Window_(title=u'Microsoft SQL Server Management Studio', class_name='wndclass_desked_gsk')
window.Wait('ready', timeout=20) # default timeout is 5 sec. if any
ctrl = window['TreeView']
ctrl.GetItem([u'SQL Server 8.0.2039']).Click() 
ctrl.GetItem([u'SQL Server 8.0.2039', u'Databases', u'Northwind']).Click() #Selecting the database

Please check how it works.

EDIT:

It seems you generated the code for 'Microsoft SQL Server Management Studio' window using SWAPY. It means that the window was already open.

But in automated workflow Log-in is quite long operation (may take up to 10 seconds I believe). So when you clicked "Connect" button, 'Microsoft SQL Server Management Studio' is not open yet. You may see some progress window or even nothing for a few seconds.

Function find_windows doesn't wait while the window appears on the screen. It just finds the window at that moment. So when you execute line

window = pwa_app.Window_(title=u'Microsoft SQL Server Management Studio', class_name='wndclass_desked_gsk')

WindowSpecification object is created (window variable). ctrl = window['TreeView'] is also WindowSpecification object. They are just descriptions and are not connected with real window/control. But the following statement

ctrl.GetItem([u'SQL Server 8.0.2039']).Click()

is equivalent to

ctrl.WrapperObject().GetItem([u'SQL Server 8.0.2039']).Click() 

or

ctrl.Wait('visible').GetItem([u'SQL Server 8.0.2039']).Click()

pywinauto hides WrapperObject() call using power of Python. So it's called automatically. Default timeout is 5 seconds in this case. It might be insufficient for long time operations like Log-in. That's why I suggest calling Wait('ready', timeout=20) explicitly. 'ready' means 'exists visible enabled' using logical AND.

Post a Comment for "Automation Microsoft Sql Server 2008 R2 Using Python(pywinauto)"