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(Databases). I need to do much more, clicking the child_tree(Northwind) right click option (Ex. Tasks-> backup). Help me to do the best automation code. Thanks 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 the 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 the .exe file
print("Status: Application Launched successfully!!")
except:
print("Error: Applicatin Launching Error!!")
try:
pwa_app.ConnecttoServer.ComboBox1.Select("Database Engine") #Selecting the 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 into 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 the database
except:
print("Database selection failed !!")
else: print 'Dear', host,'You are not Authorized to Run this program\n'