自动化的Microsoft SQL Server 2008 R2使用Python(pywinauto)
我创建的的Microsoft SQL Server Management Studio中 自动化工具使用python 。问题是我无法选择的 Child_tree (罗斯文)数据库,它选择在 Parent_tree (数据库)。我需要做更多,点击child_tree(罗斯文)右击选择(出任务 - >备份)。帮我做最好的自动化code。
提前致谢。
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:
其他:
打印亲爱的,主持人,你无权运行此程序\\ n
else: print 'Dear', host,'You are not Authorized to Run this program\n'
由于我可以评论明白,你需要等到主窗口登录后打开。
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.
修改
看来你产生code使用SWAPY 的Microsoft SQL Server Management Studio中
窗口。这意味着窗口已经打开。
It seems you generated the code for 'Microsoft SQL Server Management Studio'
window using SWAPY. It means that the window was already open.
但在自动化的工作流程登录
很长操作(可能需要长达10秒,我相信)。所以,当你点击连接按钮,的Microsoft SQL Server Management Studio中
尚未开放。您可能会看到几秒钟一些进展的窗口,甚至什么都没有。
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.
功能 find_windows
不同时,在屏幕上出现的窗口等待。它只是发现窗口的那一刻。所以,当你执行行
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 创建对象(窗口
变量)。 CTRL =窗口['的TreeView']
也WindowSpecification对象。他们只是说明,不与真正的窗口/控制连接。但是,下面的语句
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()
等同于
ctrl.WrapperObject().GetItem([u'SQL Server 8.0.2039']).Click()
或
ctrl.Wait('visible').GetItem([u'SQL Server 8.0.2039']).Click()
pywinauto皮 WrapperObject()
使用Python的力量召唤。因此,它自动调用。默认超时是在这种情况下,5秒钟。这可能不足以满足像日志,在很长一段时间的操作。这就是为什么我建议叫等待('准备好',超时= 20)
明确。 '准备好'
办法'存在明显的启用
使用逻辑和
。
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
.