我正在尝试自动化一些基本的Putty活动,比如使用pywinauto登录系统并输入一些命令。只想让你知道-我不认为paramiko/netmiko可以帮助我,因为我需要在屏幕上的窗口停留(GUI),以便我可以继续工作在同一窗口作为代码运行的结果。
我的代码启动到给定ip (10.22.22.222)的会话。但是,我有时会看到一些对话框窗口,例如安全警告(如果这是我第一次登录到给定的计算机)或致命错误(如果设备无法访问或连接被拒绝)。有谁知道如何处理/按下此窗口上的按钮,如“是”、“否”、“取消”、“确定”或“关闭”。
我的代码片段如下:
app = Application().Start('C:\\Users\\redback\\Desktop\\putty.exe -ssh admin@10.22.22.222')
pt = app.PuTTY
pt.Wait ('ready')
time.sleep (40) # tried to wait 40 secs (more than the default timeout of 30 secs)
pt.PuTTY.OK.click() # and press OK on the PuTTY Fatal Error pop-up window
# ideally I would carry on with Alt+F4 or Close so that I can clean it off the screen非常感谢。
发布于 2018-04-21 19:19:29
我认为下面的代码应该可以处理弹出窗口。
app = Application().Start(r"C:\Program Files\PuTTY\putty.exe -ssh admin@192.168.1.1")
pt = app.PuTTY
pt_sec_alert = app.PuTTYSecurityAlert
pt.wait('ready')
time.sleep(5)
if pt_sec_alert.exists():
# pt_sec_alert.Yes.click()
# pt_sec_alert.No.click()
pt_sec_alert.Cancel.click()这是安全警报窗口的示例,对于致命错误,我认为它将是相同的。
https://stackoverflow.com/questions/49953231
复制相似问题