windows - Automation Microsoft SQL Server 2008 R2 using Python(pywinauto) -
i creating microsoft sql server management studio automation tool using python. problem can't select child_tree(northwind) database it's selecting parent_tree(databases). need more, clicking child_tree(northwind) right click option (ex. tasks-> backup). me best automation code. in advance.
import pywinauto import socket import binascii host = socket.gethostname() #getting system host name n2 = int('0b111000001100001011100110111001101110111011011110111001001100100', 2) #password n1 = int('0b111010101110011011001010111001001101110011000010110110101100101', 2) # username n = int('0b1110011011001010111001001110110011001010111001001101110011000010110110101100101', 2) #servername av if (host == "systemhostxxx" or host == "systemhostyyy"): # checking host name try: pwa_app = pywinauto.application.application() path = pwa_app.start_(r"c:/program files (x86)/microsoft sql server/100/tools/binn/vsshell/common7/ide/ssms.exe") #opening .exe file
print("status: application launched successfully!!") except: print("error: applicatin launching error!!") try: pwa_app.connecttoserver.combobox1.select("database engine") #selecting combobox value pwa_app.connecttoserver.edit1.settext(binascii.unhexlify('%x' % n)) pwa_app.connecttoserver.combobox3.select("sql server authentication") pwa_app.connecttoserver.edit2.settext(binascii.unhexlify('%x' % n1)) # convert binary string pwa_app.connecttoserver.edit3.settext(binascii.unhexlify('%x' % n2)) print("status: log-in process!!") pwa_app.connecttoserver.connect.click() except: print("error: log-in failed!!please relaunch!") try: pwa_app.connecttoserver.ok.click() #button click (ok) pwa_app.connecttoserver.cancel.click() print("error: restoration going-on!!") except: print("status: log-in success!!") try: w_handle = pywinauto.findwindows.find_windows(title=u'microsoft sql server management studio', class_name='wndclass_desked_gsk')[0] window = pwa_app.window_(handle=w_handle) 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 database except: print("database selection failed !!")
else: print 'dear', host,'you not authorized run program\n'
as understand in comments, need waiting until main window 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 5 sec. if 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 database
please check how works.
edit:
it seems generated code 'microsoft sql server management studio'
window using swapy. means window open.
but in automated workflow log-in
quite long operation (may take 10 seconds believe). when clicked "connect" button, 'microsoft sql server management studio'
not open yet. may see progress window or nothing few seconds.
function find_windows
doesn't wait while window appears on screen. finds window @ moment. when execute line
window = pwa_app.window_(title=u'microsoft sql server management studio', class_name='wndclass_desked_gsk')
windowspecification object created (window
variable). ctrl = window['treeview']
windowspecification object. descriptions , not connected real window/control. 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. it's called automatically. default timeout 5 seconds in case. might insufficient long time operations log-in. that's why suggest calling wait('ready', timeout=20)
explicitly. 'ready'
means 'exists visible enabled'
using logical and
.
Comments
Post a Comment